aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <Alexander.Pickering@anondomain.site90.net>2016-01-23 00:21:58 -0500
committerAlexander Pickering <Alexander.Pickering@anondomain.site90.net>2016-01-23 00:21:58 -0500
commit9b1057243fe1db65f351e213f00e41ceca67a8da (patch)
treed0d0982175639baaad0a28fee64c5dcbc41c11b9
parente8439ad503f530724f1eae2de1a8ac2c19df52c0 (diff)
downloadwintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.tar.gz
wintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.tar.bz2
wintersurvival2-9b1057243fe1db65f351e213f00e41ceca67a8da.zip
Completed basic framework for setting up spells, and minigames for casting
-rw-r--r--gamemode/hud/draw_spell.lua105
-rw-r--r--gamemode/hud/games/base.lua9
-rw-r--r--gamemode/hud/games/connectthedots.lua25
-rw-r--r--gamemode/itemsystem/items/spell_fireball.lua31
-rw-r--r--gamemode/npcsystem/npcs/antlion4.lua2
-rw-r--r--gamemode/shared/player_spellcast.lua45
6 files changed, 172 insertions, 45 deletions
diff --git a/gamemode/hud/draw_spell.lua b/gamemode/hud/draw_spell.lua
index 032c25f..96440e4 100644
--- a/gamemode/hud/draw_spell.lua
+++ b/gamemode/hud/draw_spell.lua
@@ -2,48 +2,67 @@ CASTING_SPELL = nil
--AddLUACSFolder("spellminigames")
-local Folder = GM.Folder:gsub("gamemodes/","").."/gamemode/hud/"
+local Folder = GM.Folder:gsub("gamemodes/","").."/gamemode/hud/games"
--A table of spells to functions?
-Spells = {}
---[[
- ["fireball"] = {
- ["minigame"] = connectthedots,
- ["interupt"] = connectextradots,
- ["difficulty"] = 1
- }
-}]]--
+Spells = {
+ ["Fireball"] = {
+ ["file"] = "connectthedots.lua",
+ ["minigame"] = "Cast",
+ ["interupt"] = "AddDots",
+ ["draw"] = "Draw",
+ ["difficulty"] = 1,
+ },
+}
+
+Games = {}
function loadgames()
- GAMEMODE.minigames = {}
- print("WS2A:Looking for minigames in:" .. Folder)
- AddCSLuaFile(Folder .. "/games/base.lua")
- include(Folder .. "/games/base.lua")
- local games, fold = file.Find(Folder.."*","LUA")
- local game = {}
- print("WS2A:Loading " .. #(games) .. " minigames")
- print("WS2A:Found " .. #(fold) .. " folders")
- for k,v in pairs(games) do
- print(v)
- --[[
- if (v != "base.lua") then
- AddCSLuaFile(Folder.."/"..v)
- include(Folder.."/"..v)
- if((not game.Name) or (not game.minigame) or (not game.interupt)) then
- print("WS2A:Error loading " .. Folder .. "/" .. v .. "One or more of the are missing: Name, minigame, interupt")
- continue
- else
- print("WS2A:Loaded " .. Folder .. "/" .. v)
+ includedfiles = {}
+ print("Looking for what minigames we need...")
+ for k,v in pairs(Spells) do
+ local filename = v["file"]
+ if (includedfiles[filename] == nil) then
+ print("Spell " .. k .. " depends on " .. filename)
+ includedfiles[filename] = true
+ end
+ end
+ Game = {}
+ print("Loading in minigames")
+ for k,v in pairs(includedfiles) do
+ AddCSLuaFile(Folder .. "/" .. k)
+ Game = {}
+ include(Folder .. "/" .. k)
+ Games[k] = Game
+ end
+ print("Resolveing minigame names")
+ for k,v in pairs(Spells) do
+ local mgname = v["minigame"]
+ local mginame = v["interupt"]
+ local mgdname = v["draw"]
+ for i,j in pairs(Games) do
+ if i == v["file"] then
+ print("Resolved " .. k)
+ local castfunc = j[mgname]
+ local drawfunc = j[mgdname]
+ local interuptfunc = j[mginame]
+ if(castfunc) then
+ v["minigame"] = castfunc
+ else
+ print("Spell " .. k .. " does not have a cast func! This may be an error!")
+ end
+ if(drawfunc) then
+ v["draw"] = drawfunc
+ else
+ print("Spell " .. k .. " does not have a draw func! This may be an error!")
+ end
+ if(interuptfunc) then
+ v["interupt"] = interuptfunc
+ else
+ print("Spell " .. k .. " does not have an interupt func! This may be an error!")
+ end
end
-
- table.insert(GAMEMODE.Spells,{
- Spell.Name
- })
-
- NPC = table.Copy(BaseItem)
-
end
- ]]--
end
end
@@ -60,13 +79,13 @@ function StartMinigame(spell)
if not spell then return end
--If we're already casting, and are told to cast again do someting.
if CASTING_SPELL != nil then
- CASTING_SPELL["interupt"]()
+ CASTING_SPELL["interupt"](CASTING_SPELL)
return
end
- if spells[spell] then
- CASTING_SPELL = spells[spell]
- spells[spell]["minigame"](spells[spell]["difficulty"])
+ if Spells[spell] then
+ CASTING_SPELL = Spells[spell]
+ Spells[spell]["minigame"](CASTING_SPELL, Spells[spell]["difficulty"])
else
print("Could not find spell " .. spell)
end
@@ -74,7 +93,11 @@ end
function DrawSpellOverlay()
if(CASTING_SPELL) then
- CASTING_SPELL["minigame"]()
+ CASTING_SPELL["draw"](CASTING_SPELL)
+ if(CASTING_SPELL.Score != nil) then
+ finishedcasting(CASTING_SPELL.Score)
+ CASTING_SPELL = nil
+ end
end
end
diff --git a/gamemode/hud/games/base.lua b/gamemode/hud/games/base.lua
index a6c68c1..a3d0938 100644
--- a/gamemode/hud/games/base.lua
+++ b/gamemode/hud/games/base.lua
@@ -1,2 +1,11 @@
--A file to show what functions are used for minigames
print("Base included!")
+
+--Required functions
+--Called once when the plyer starts casting
+Game.Cast = function(difficulty)
+end
+
+--Called continuously while the player is casting
+Game.Draw = function()
+end
diff --git a/gamemode/hud/games/connectthedots.lua b/gamemode/hud/games/connectthedots.lua
index c24ff14..9b89d70 100644
--- a/gamemode/hud/games/connectthedots.lua
+++ b/gamemode/hud/games/connectthedots.lua
@@ -1,7 +1,26 @@
--The connet the dots spell game
print("Hi from connectthedots.lua")
-function connectthedots()
- print("Blah!")
- return 100
+Game.Cast = function(self,difficulty)
+ print("Cast with dificulty: " .. difficulty)
+ self.Score = nil
+end
+
+Game.Draw = function(self)
+ if not input.IsKeyTrapping() then
+ input.StartKeyTrapping()
+ end
+ draw.DrawText( "You're casting a spell!", "TargetID", ScrW() * 0.5, ScrH() * 0.25, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )
+ print("X:" .. gui.MouseX() .. " Y:" .. gui.MouseY())
+ if(input.IsMouseDown(MOUSE_RIGHT)) then
+ self.Score = 100
+ end
+end
+
+Game.AddDots = function(self)
+ print("Add dots function called!")
+end
+
+Game.InstantFail = function(self)
+ self.Score = 0
end
diff --git a/gamemode/itemsystem/items/spell_fireball.lua b/gamemode/itemsystem/items/spell_fireball.lua
new file mode 100644
index 0000000..d8bad79
--- /dev/null
+++ b/gamemode/itemsystem/items/spell_fireball.lua
@@ -0,0 +1,31 @@
+
+ITEM.Name = "Fireball"
+ITEM.Class = "weapon"
+ITEM.Desc = "Warning: Warm"
+ITEM.Model = "models/props_debris/wood_board02a.mdl"
+ITEM.Icon = Material("wintersurvival2/hud/ws1_icons/icon_bow")
+ITEM.HoldType = "magic"
+
+ITEM.Recipe = {
+ Resources = {
+ ["Plank"] = 2,
+ ["Rope"] = 1,
+ ["Sap"] = 1,
+ },
+ Tools = {},
+}
+
+ITEM.CD = 1
+
+function ITEM:DoFireball()
+ print("Fully successfull fireball callback")
+end
+
+function ITEM:DoFireballFail()
+
+end
+
+function ITEM:OnPrimary(pl,tr)
+ if (CLIENT) then return end
+ pl:Cast("Fireball",self.DoFireball)
+end
diff --git a/gamemode/npcsystem/npcs/antlion4.lua b/gamemode/npcsystem/npcs/antlion4.lua
index e8e7a88..cb39049 100644
--- a/gamemode/npcsystem/npcs/antlion4.lua
+++ b/gamemode/npcsystem/npcs/antlion4.lua
@@ -13,7 +13,7 @@ NPC.Stats = {
["Accel"] = 400,
["Decel"] = 400,
["Step"] = 20, --Step height
- ["Hull"] = HULL_LARGE
+ ["Hull"] = HULL_LARGE,
["TargetBuildings"] = true
}
diff --git a/gamemode/shared/player_spellcast.lua b/gamemode/shared/player_spellcast.lua
new file mode 100644
index 0000000..fcc9484
--- /dev/null
+++ b/gamemode/shared/player_spellcast.lua
@@ -0,0 +1,45 @@
+
+local meta = FindMetaTable("Player")
+
+--Number of bits used for networking spell casting success rate. Even though by default it shouldn't be more than 100, 8 lets it go to 256 in case you want to add buffs/bonuses.
+local BITCOUNT = 256
+
+if(SERVER) then
+ util.AddNetworkString("CastSpell")
+ util.AddNetworkString("FinishedCasting")
+
+ function meta:Cast(spellname, callback)
+ if(self.casting) then return end
+ self.casting = callback
+ print("Casting " .. spellname)
+ net.Start("CastSpell")
+ net.WriteString(spellname)
+ net.Send(self)
+ end
+
+ net.Receive("FinishedCasting",function(len,pl)
+ if(pl.casting) then
+ print("Finished casting message received by server")
+ pl.casting(net.ReadInt(BITCOUNT))
+ pl.casting = nil
+ end
+ end)
+else
+
+ function finishedcasting(score)
+ net.Start("FinishedCasting")
+ net.WriteInt(score,BITCOUNT)
+ net.SendToServer()
+ end
+
+ net.Receive("CastSpell",function()
+ local spellname = net.ReadString()
+ print("Request to cast spell" .. spellname)
+ StartMinigame(spellname)
+ end)
+end
+
+function meta:IsCasting()
+ if(self.casting) then return false end
+ return true
+end