diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-10-29 17:51:13 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-10-29 17:51:13 -0400 |
| commit | 79c1c484eab6fbf36a69d155a324540887e38880 (patch) | |
| tree | 87f4e64fcc4331ab304e65a531c28b9802e69784 /gamemode | |
| parent | 78e40d9fd55b6ba23db4f459e2c7e9ae2109cf5a (diff) | |
| download | artery-79c1c484eab6fbf36a69d155a324540887e38880.tar.gz artery-79c1c484eab6fbf36a69d155a324540887e38880.tar.bz2 artery-79c1c484eab6fbf36a69d155a324540887e38880.zip | |
Got shops working
Diffstat (limited to 'gamemode')
| -rw-r--r-- | gamemode/client/cl_inventory.lua | 5 | ||||
| -rw-r--r-- | gamemode/client/cl_weaponswitch.lua | 4 | ||||
| -rw-r--r-- | gamemode/client/qpanels/inventory.lua | 5 | ||||
| -rw-r--r-- | gamemode/init.lua | 23 | ||||
| -rw-r--r-- | gamemode/server/sv_config.lua | 4 | ||||
| -rw-r--r-- | gamemode/server/sv_mapconfig.lua | 1 | ||||
| -rw-r--r-- | gamemode/shared/inventory.lua | 63 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/armor/balaclava.lua | 1 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/exampleitem.lua | 2 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/foodstuffs/ratmeat.lua | 4 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/foodstuffs/watermelon.lua | 2 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/item_common.lua | 76 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/quest/rougebook.lua | 11 | ||||
| -rw-r--r-- | gamemode/shared/itemsystem/weapons/rustyaxe.lua | 1 | ||||
| -rw-r--r-- | gamemode/shared/loadprayers.lua | 2 | ||||
| -rw-r--r-- | gamemode/shared/npcsystem/rat.lua | 6 | ||||
| -rw-r--r-- | gamemode/shared/shop.lua | 138 |
17 files changed, 325 insertions, 23 deletions
diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua index b806846..a40a5f8 100644 --- a/gamemode/client/cl_inventory.lua +++ b/gamemode/client/cl_inventory.lua @@ -7,6 +7,11 @@ print("Hello from cl_inventory.lua") ART.PrayerEquiped = ART.PrayerEquiped or { false,false,false,false } +net.Receive("equiphelpprayer",function() + print("equiphelp received client side!") + ART.PrayerEquiped[4] = "Noob Help" +end) + local lastpanel = lastpanel or 1 diff --git a/gamemode/client/cl_weaponswitch.lua b/gamemode/client/cl_weaponswitch.lua index 5aaed87..f7edcfc 100644 --- a/gamemode/client/cl_weaponswitch.lua +++ b/gamemode/client/cl_weaponswitch.lua @@ -1,3 +1,7 @@ function GM:PlayerSwitchWeapon( ply, oldWeapon, newWeapon ) return false end + +hook.Add( "HUDShouldDraw", "HideWeaponSelHUD", function( name ) + if name == "CHudWeaponSelection" then return false end +end ) diff --git a/gamemode/client/qpanels/inventory.lua b/gamemode/client/qpanels/inventory.lua index 9fec1cc..b366c7a 100644 --- a/gamemode/client/qpanels/inventory.lua +++ b/gamemode/client/qpanels/inventory.lua @@ -82,7 +82,10 @@ local function DrawBackpackOnDPanel(dp, backpack, backpacknum, tent) if invfuncs.CanFitInBackpack(backpack,j,i,item) then local fromtbl = icon.invpos local wasequiped = icon.wasequiped - if wasequiped then + local ondropped = icon.ondropped + if ondropped then + ondropped(backpacknum,j,i,item) + elseif wasequiped then net.Start("unequipitem") net.WriteString(wasequiped) net.WriteUInt(backpacknum,16) diff --git a/gamemode/init.lua b/gamemode/init.lua index 0b311ea..b4f5c76 100644 --- a/gamemode/init.lua +++ b/gamemode/init.lua @@ -3,3 +3,26 @@ AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "cl_init.lua" ) include( "shared.lua" ) + +local pmeta = FindMetaTable("Player") + +--- Loads a player's inventory +-- @param json The JSON string to create the player's inventory from +function pmeta:LoadInventory(json) + local reinv = util.JSONToTable(json) + for k,v in pairs(reinv) do + self.Inventory[k] = v + end + print("After loading inventory, player's inventory was") + PrintTable(self.Inventory) + self:SynchronizeInventory() + self:SynchPrayers() + if self:HasPrayer("Noob Help") then + print("Player had Noob Help, equiping!") + net.Start("equiphelpprayer") + net.Send(self) + else + error("Player did not have noob help, inventory was:") + PrintTable(self.Inventory) + end +end diff --git a/gamemode/server/sv_config.lua b/gamemode/server/sv_config.lua index cb365a6..82f1061 100644 --- a/gamemode/server/sv_config.lua +++ b/gamemode/server/sv_config.lua @@ -3,10 +3,10 @@ ]] ART.defaults = {} -ART.defaults.starting_inventory = '{"Backpacks":[[[[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false]],[5,5],"Rucksack"]],"Equiped":{"Gloves":false,"Left":false,"Head":false,"Legs":false,"Right":false,"Body":false,"Boots":false}}' +ART.defaults.starting_inventory = '{"Backpacks":[[[[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false],[false,false,false,false,false]],[5,5],"Rucksack"]],"Credits":0,"Equiped":{"Gloves":false,"Left":false,"Boots":false,"Legs":false,"Right":false,"Body":false,"Head":false},"Prayers":{"Noob Help":true}}' ART.defaults.starting_skills = "[]" ART.defaults.starting_quests = "[]" -ART.defaults.starting_prayers = "[]" +ART.defaults.starting_prayers = "[]" --This dosen't actually do anything, remove it at some point. ART.defaults.starting_position = "185 310 524" ART.defaults.starting_world = "0.0.0.0:27015" diff --git a/gamemode/server/sv_mapconfig.lua b/gamemode/server/sv_mapconfig.lua index b9a93b8..7117a07 100644 --- a/gamemode/server/sv_mapconfig.lua +++ b/gamemode/server/sv_mapconfig.lua @@ -21,6 +21,7 @@ local removeents = { "npc_townie", -- "art_chest", "info_townienode", + "npc_shop", } for k,v in pairs(removeents) do diff --git a/gamemode/shared/inventory.lua b/gamemode/shared/inventory.lua index a8c1756..2165686 100644 --- a/gamemode/shared/inventory.lua +++ b/gamemode/shared/inventory.lua @@ -1,5 +1,7 @@ --[[ Various functions to work with inventories + player:GetCredits() + player:SetCredits(number credits) ]] --- Various functions to deal with inventories. -- @module Player @@ -159,6 +161,7 @@ if SERVER then util.AddNetworkString("moveitem") util.AddNetworkString("equipitem") util.AddNetworkString("unequipitem") + util.AddNetworkString("buyitem") end --- Unequips an item. @@ -169,14 +172,16 @@ end -- @param col The column in the backpack to put the item function pmeta:UnEquip(equipslot, backpack, row, col) local item = self.Inventory.Equiped[equipslot] + local tobackpack = self.Inventory.Backpacks[backpack] + print("Unequiping into backpack", tobackpack) if self:CanFitInBackpack( - self.Inventory.Backpacks[backpack], + tobackpack, row, col, item ) then self.Inventory.Equiped[equipslot] = false - self:PutInvItem(tobackpack,row,col,item) + self:PutInvItem(backpack,row,col,item) if item.onUnEquip ~= nil then item:onUnEquip(self) end @@ -228,6 +233,50 @@ net.Receive("equipitem",function(len,ply) ply:EquipItem(backpacknum,fromrow,fromcol,equippos) end) +net.Receive("buyitem",function(len,ply) + local itemname = net.ReadString() + local backpack = net.ReadUInt(8) + local j = net.ReadUInt(8) + local i = net.ReadUInt(8) + local item = ART.GetItemByName(itemname) + local nearshops = ents.FindInSphere( ply:GetPos(), 100 ) + local cost + for k,v in pairs(nearshops) do + if v:GetClass() ~= "npc_shop" then goto nextent end + print("Checking if ", v, " has a ", itemname) + print("Shop items were") + PrintTable(v.shopitems) + for i,j in pairs(v.shopitems) do + if j[1] == itemname then + cost = j[2] + goto itemfound + end + end + ::nextent:: + end + ::itemfound:: + if cost == nil then + ply:ChatPrint("Could not find a shop selling that!") + return false + end + print("Found item, cost was ", cost) + local playercreds = ply:GetCredits() + local tbp = ply.Inventory.Backpacks[backpack] + local canfit = invfuncs.CanFitInBackpack(tbp,j,i,item) + print("Can it?",canfit) + if playercreds < cost then + ply:ChatPrint("You don't have enough credits to buy that!") + return false + end + if not canfit then + ply:ChatPrint("You can't put that into your packpack there!") + return false + end + playercreds:SetCredits(playercreds - cost) + invfuncs.PutItemInBackpack(tbp,j,i,item) + return true +end) + net.Receive("moveitem",function(len,ply) local froment = net.ReadEntity() local toent = net.ReadEntity() @@ -262,16 +311,6 @@ net.Receive("moveitem",function(len,ply) toent:SynchronizeInventory() end) ---- Loads a player's inventory --- @param json The JSON string to create the player's inventory from -function pmeta:LoadInventory(json) - local reinv = util.JSONToTable(json) - for k,v in pairs(reinv) do - self.Inventory[k] = v - end - self:SynchronizeInventory() -end - --- Networks a player's inventory -- Makes sure the client's version of the inventory matches up to the server's version, this should be called after manipulateing the client's inventory in any way. function pmeta:SynchronizeInventory() diff --git a/gamemode/shared/itemsystem/armor/balaclava.lua b/gamemode/shared/itemsystem/armor/balaclava.lua index d77da61..8b4b8d2 100644 --- a/gamemode/shared/itemsystem/armor/balaclava.lua +++ b/gamemode/shared/itemsystem/armor/balaclava.lua @@ -26,6 +26,7 @@ function item.GetOptions(self) local options = {} options["test"] = function() print("You pressed test!") end options["toste"] = function() print("You pressed toste!") end + options["drop"] = ART.DropItem(self) return options end diff --git a/gamemode/shared/itemsystem/exampleitem.lua b/gamemode/shared/itemsystem/exampleitem.lua index fdc0e9c..a21def8 100644 --- a/gamemode/shared/itemsystem/exampleitem.lua +++ b/gamemode/shared/itemsystem/exampleitem.lua @@ -75,7 +75,7 @@ item.onUnEquip = function(self,who) print("Aw, I'm being stored :(") end ---Technically optional, but item will display as a rock if you don't have it +--Technically optional, but item will display as a rock if you don't have it. If you want to do something other than drop on dropped, remove ent. item.onDropped = function(self,ent) print("I've been dropped!(BUVVV WUB WUB WUB WUB WUB)") end diff --git a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua b/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua index 8990a49..5310fe2 100644 --- a/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua +++ b/gamemode/shared/itemsystem/foodstuffs/ratmeat.lua @@ -39,6 +39,8 @@ item.Shape = { {true} } - +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"ratmeat") +end --Don't forget to register the item! ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua b/gamemode/shared/itemsystem/foodstuffs/watermelon.lua index c79ba6c..2b9f7cb 100644 --- a/gamemode/shared/itemsystem/foodstuffs/watermelon.lua +++ b/gamemode/shared/itemsystem/foodstuffs/watermelon.lua @@ -47,7 +47,7 @@ item.Shape = { } item.onDropped = function(self, ent) - ART.ApplyPAC(ent,"scraphammer") + ART.ApplyPAC(ent,"Watermelon") end print("Hello from exampleitem.lua") diff --git a/gamemode/shared/itemsystem/item_common.lua b/gamemode/shared/itemsystem/item_common.lua new file mode 100644 index 0000000..b4b7cce --- /dev/null +++ b/gamemode/shared/itemsystem/item_common.lua @@ -0,0 +1,76 @@ +if CLIENT then + ART.DropItem = function(item) + local i = item + print("Trying to drop item, Item was ") + PrintTable(item) + return function() + local data = item:Serialize() + net.Start("dropitem") + net.WriteString(item.Name) + net.WriteUInt(#data,32) + net.WriteData(data,#data) + net.SendToServer() + end + end + +else + util.AddNetworkString("dropitem") + + function gencompareto(item) + --Two items are equal if their Serialize()s are the same. + local tserialize = item:Serialize() + return function(otheritem) + local oserialize = otheritem:Serialize() + return tserialize == oserialize + end + end + + function ART.CreateDroppedItem(itemtbl, where) + local e = ents.Create("art_droppeditem") + e.Model = "models/props_junk/Rock001a.mdl" + e.Item = itemtbl + e:SetPos(where) + e:Spawn() + end + + net.Receive("dropitem",function(len,ply) + local itemtype = net.ReadString() + local itemdatalen = net.ReadUInt(32) + local itemdata = net.ReadData(itemdatalen) + local itemtbl = ART.GetItemByName(itemtype) + local item = itemtbl:DeSerialize(itemdata) + + print("I want to drop:") + PrintTable(item) + print("Do I have one?") + local row,col,n = ply:HasItem(gencompareto(item)) + print("row",row,"col",col,"n",n) + --To find out where to drop the item, go out from player's view, then down. + local pes = ply:GetPos()+Vector(0,0,64) + local pee = ply:GetForward()*50 + Vector(0,0,64) + ply:GetPos() + local tr1d = { + ["start"] = pes, + ["endpos"] = pee, + ["filter"] = ply, + } + local tr1r = util.TraceLine(tr1d) + local fes + if tr1r.hit then --Use where it hit and go down + fes = tr1r.HitPos + else --Use the spot 50 units in front of us + fes = pee + end + local tr2d = { + ["start"] = fes, + ["endpos"] = fes + Vector(0,0,-64), + } + local tr2r = util.TraceLine(tr2d) + local itempos = tr2r.HitPos + print("Dropping item at",itempos) + if row and col and n then + print("DropItem is",ART.DropItem) + ART.CreateDroppedItem(item,itempos) + ply:RemoveItemAt(n,row,col) + end + end) +end diff --git a/gamemode/shared/itemsystem/quest/rougebook.lua b/gamemode/shared/itemsystem/quest/rougebook.lua index 835b863..4eabe06 100644 --- a/gamemode/shared/itemsystem/quest/rougebook.lua +++ b/gamemode/shared/itemsystem/quest/rougebook.lua @@ -22,11 +22,14 @@ item.Shape = { local rougeadvice = { "He who refuses to trim his beard will find himself in a hairy situation.", - "You'll get tired defending from a man in a vehicle", - "You'll get exhaused attacking a man in a vehicle.", + "You'll get tired defending from a man in a car", + "You'll get exhaused attacking a man in a car.", + "Sex is not the answer, it is the question. And the answer is 'yes'.", + "The 'Darkest Hour' is when you can't find the matches.", "If you eat beans before church, you will sit in your own pew.", "He who seeks challenges will be puzzeled.", "He who fishes in another man's well is likely to catch crabs.", + "Enjoy masturbation, it's sex with someone you love.", } local lhint = 1 @@ -58,4 +61,8 @@ function item.GetOptions(self) return options end +item.onDropped = function(self, ent) + ART.ApplyPAC(ent,"book1") +end + ART.RegisterItem(item) diff --git a/gamemode/shared/itemsystem/weapons/rustyaxe.lua b/gamemode/shared/itemsystem/weapons/rustyaxe.lua index f21500d..735c3da 100644 --- a/gamemode/shared/itemsystem/weapons/rustyaxe.lua +++ b/gamemode/shared/itemsystem/weapons/rustyaxe.lua @@ -26,6 +26,7 @@ function item.GetOptions(self) local options = {} options["test"] = function() print("You pressed test!") end options["toste"] = function() print("You pressed toste!") end + options["Drop"] = ART.DropItem(self) return options end diff --git a/gamemode/shared/loadprayers.lua b/gamemode/shared/loadprayers.lua index 53631c2..3c94b72 100644 --- a/gamemode/shared/loadprayers.lua +++ b/gamemode/shared/loadprayers.lua @@ -69,6 +69,8 @@ if SERVER then end util.AddNetworkString( "art_synch_prayers" ) + util.AddNetworkString( "equiphelpprayer" ) + function meta:SynchPrayers() print("Sending " .. table.Count(self.Inventory.Prayers) .. " prayers:") PrintTable(self.Inventory.Prayers) diff --git a/gamemode/shared/npcsystem/rat.lua b/gamemode/shared/npcsystem/rat.lua index d1c5422..ab96883 100644 --- a/gamemode/shared/npcsystem/rat.lua +++ b/gamemode/shared/npcsystem/rat.lua @@ -23,8 +23,8 @@ NPC.IdleSequences = { --Drops should be formated as [index]={["item name"], percent_drop} where percent_drop is a number from 0 to 100 NPC.Drops = { - [0] = {"Meat",100},--Rats will drop at least 1 meat, and have a 50% chance of dropping 2 - [1] = {"Meat",50}, + [0] = {"Rat Meat",100},--Rats will drop at least 1 meat, and have a 50% chance of dropping 2 + [1] = {"Rat Meat",50}, } --Attacks should be formated as [i]={function attackpriority() = function doattack()} @@ -47,7 +47,7 @@ local dorun = function(self,ply) direction:Normalize() local addition = direction * 1000 local topos = self:GetPos() + addition - print("I want to go to ", topos) + --print("I want to go to ", topos) self.TargetPos = topos end NPC.Attacks = { diff --git a/gamemode/shared/shop.lua b/gamemode/shared/shop.lua new file mode 100644 index 0000000..b188e7c --- /dev/null +++ b/gamemode/shared/shop.lua @@ -0,0 +1,138 @@ +local ivf = include("inventory_common.lua") +ART = ART or {} + +if SERVER then + for k,v in pairs({ + "art_openshop", + "art_buyitem", + "art_sellitem", + }) do + util.AddNetworkString(v) + end + + function ART.OpenShop(tbl, ply) + print("Called openshop!") + print("tbl was") + PrintTable(tbl) + if CLIENT then return end + net.Start("art_openshop") + net.WriteTable(tbl) + net.Send(ply) + end + + function ART.CreateShop(npc) + print("Createing shop npc") + local npcent = ents.Create("npc_shop") + for k,v in pairs(npc) do + npcent[k] = v + end + npcent:Spawn() + print("Called spawn") + end + +end + +if SERVER then return end +local w,h = ScrW(),ScrH() +function DrawShopItemOnDPanel(dp,item) + --An item is a string, and int cost + local itemtbl = ART.GetItemByName(item[1]) + local cost = item[2] + + local shape = itemtbl.Shape + local twidth,theight = 0,#shape + for k=1,#shape do + twidth = math.max(twidth,#shape[k]) + end + + local slotsize = math.Round(w / 32) + local backgrid = vgui.Create( "DGrid", dp ) + backgrid:SetPos( 10, 30 ) + backgrid:SetCols( twidth ) + backgrid:SetColWide( theight ) + backgrid:Dock(FILL) + + local shopicon = vgui.Create( "DImageButton", dp ) + shopicon:SetSize(slotsize * twidth, slotsize * theight) + shopicon:SetPos(0,0) + shopicon:SetText(itemtbl.Name) + if itemtbl.Tooltip then + shopicon:SetTooltip(itemtbl.Tooltip) + end + if itemtbl.Paint then + shopicon.Paint = itemtbl.Paint + end + if itemtbl.DoOnPanel then + itemtbl.DoOnPanel(shopicon) + end + --invicon.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,100,0)) end + shopicon.DoClick = function() + print("You cliked me!") + end + shopicon.Item = itemtbl + shopicon.Cost = cost + shopicon:Droppable("Inventory") + shopicon.ondropped = function(back,j,i,item) + print("ondropped was called!") + print("back",back,"j",j,"i",i,"item",item) + PrintTable(item) + net.Start("buyitem") + net.WriteString(item.Name) + net.WriteUInt(back,8) + net.WriteUInt(j,8) + net.WriteUInt(i,8) + net.SendToServer() + end + + print("Displaying shape:") + PrintTable(shape) + for k = 1, twidth do + for i = 1, theight do + if not shape[k][i] then + print("Found false spot:",k,i) + local emptyslot = vgui.Create("DPanel", dp) + emptyslot:SetSize(slotsize,slotsize) + emptyslot:SetPos(slotsize * (i - 1), slotsize * (k - 1)) + end + end + end + +end + +function DrawShopOnDPanel(dp,items) + --This gets pretty involved, lets try to not make it a clusterfuck. + DrawShopItemOnDPanel(dp,items[1]) + +end + +local shopwindow,shoppanel + +local function createshopwindow() + print("Createing shopwindow") + shopwindow = vgui.Create( "DFrame" ) + shopwindow:SetPos( w - (w / 4), 0 ) + shopwindow:SetSize( w / 4, h ) + shopwindow:SetTitle( "Unset shop" ) + shopwindow:SetDraggable( true ) + shopwindow.OnClose = function(self) + self:SetVisible(false) + print("After onclose, shopwindow was",shopwindow) + end + shopwindow:SetVisible(false) + + shoppanel = vgui.Create( "DPanel",shopwindow) + shoppanel:SetPos( 10, 30 ) -- Set the position of the panel + shoppanel:Dock(FILL) +end +createshopwindow() + +net.Receive("art_openshop",function() + print("shopwindows was ",shopwindow) + if not shopwindow:IsValid() then createshopwindow() end + assert(shopwindow,"Shopwindow was not created, even after re-createing!") + ShowInventory() + shopwindow:SetVisible(true) + local stock = net.ReadTable() + DrawShopOnDPanel(shoppanel,stock) + shopwindow:MakePopup() +end) |
