aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-10-29 17:51:13 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-10-29 17:51:13 -0400
commit79c1c484eab6fbf36a69d155a324540887e38880 (patch)
tree87f4e64fcc4331ab304e65a531c28b9802e69784 /gamemode/shared
parent78e40d9fd55b6ba23db4f459e2c7e9ae2109cf5a (diff)
downloadartery-79c1c484eab6fbf36a69d155a324540887e38880.tar.gz
artery-79c1c484eab6fbf36a69d155a324540887e38880.tar.bz2
artery-79c1c484eab6fbf36a69d155a324540887e38880.zip
Got shops working
Diffstat (limited to 'gamemode/shared')
-rw-r--r--gamemode/shared/inventory.lua63
-rw-r--r--gamemode/shared/itemsystem/armor/balaclava.lua1
-rw-r--r--gamemode/shared/itemsystem/exampleitem.lua2
-rw-r--r--gamemode/shared/itemsystem/foodstuffs/ratmeat.lua4
-rw-r--r--gamemode/shared/itemsystem/foodstuffs/watermelon.lua2
-rw-r--r--gamemode/shared/itemsystem/item_common.lua76
-rw-r--r--gamemode/shared/itemsystem/quest/rougebook.lua11
-rw-r--r--gamemode/shared/itemsystem/weapons/rustyaxe.lua1
-rw-r--r--gamemode/shared/loadprayers.lua2
-rw-r--r--gamemode/shared/npcsystem/rat.lua6
-rw-r--r--gamemode/shared/shop.lua138
11 files changed, 286 insertions, 20 deletions
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)