1 package org
.sevenchan
.dongs
.screens
3 import org
.sevenchan
.dongs
.Item
;
4 import org
.sevenchan
.dongs
.Screen;
5 import org
.sevenchan
.dongs
.Town
;
7 import org
.sevenchan
.AdventureController
;
8 import org
.sevenchan
.dongs
.ActionNode
;
9 import org
.sevenchan
.dongs
.bodyparts
.Hair
;
10 import org
.sevenchan
.dongs
.bodyparts
.IBodyPart
;
11 import org
.sevenchan
.dongs
.Creature
;
12 import org
.sevenchan
.dongs
.enchantment
.Corruption
;
13 import org
.sevenchan
.dongs
.enchantment
.Hunger
;
14 import org
.sevenchan
.dongs
.enchantment
.Paralyze
;
15 import org
.sevenchan
.dongs
.enchantment
.WindBlessing
;
16 import org
.sevenchan
.dongs
.INode
;
17 import org
.sevenchan
.dongs
.Item
;
18 import org
.sevenchan
.dongs
.MenuNode
;
24 public class Shop
extends Encounter
26 //private var text:String = "";
27 protected var markup
:Number = 0;
28 protected var inventory
:Array = [];
29 protected var town
:Town
;
30 protected var name
:String;
31 protected var discoveredName
:String;
32 public var description
:String;
33 public var discoveredDescription
:String="A typical shop.";
34 protected var SellMenu
:MenuNode
;
36 public function Shop
(discoveredName
:String,discoveredDesc
:String,undiscoveredname
:String, undiscovereddescription
:String,t
:Town
, markup
:Number, itemsSold
:Array)
38 this.discoveredName
= discoveredName
;
39 this.discoveredDescription
= discoveredDescription
;
40 this.name
= undiscoveredname
;
41 this.description
= undiscovereddescription
;
49 currentItem
.clearChildren
();
50 var BuyItems
:MenuNode
= currentItem
.pushMenu
("Buy", "Buy things at terrible prices.");
51 for each (var item
:Item
in itemsSold
)
53 var price
:Number = item
.value
+ (item
.value
* markup
);
54 BuyItems
.pushAction
(item
.name
, price
, item
.descr
, function(ply
:Creature
, node
:ActionNode
, o
:*):Boolean
56 ply
.addToInventory
(o
as Item
);
60 SellMenu
= currentItem
.pushMenu
("Sell", "Sell things at equally terrible prices.");
64 public function updateSellMenu
():void
66 SellMenu
.clearChildren
();
67 for (var i
:int = 0; i
< main
.player
.inventory
.length
; i
++) {
68 var item
:Item
= main
.player
.inventory
[i
];
69 SellMenu
.pushAction
(item
.name
, item
.value
, item
.descr
, function(ply
:Creature
, node
:ActionNode
, o
:*):Boolean
71 ply
.addToInventory
(o
as Item
);
77 override public function processButtonPress
(id
:int):Boolean
84 text
= currentItem
.content
;
96 if (currentItem
.parent
== null)
103 currentItem
= currentItem
.parent
;
111 var nci
:INode
= currentItem
.children
[id
- 1];
112 var ret
:Boolean = false;
113 if (nci
is ActionNode
)
115 ret
= (ActionNode
(nci
)).invoke
(this, this.main
.player
, (nci
as ActionNode
).arg
);
119 if ((MenuNode
(nci
)).canSwitchTo
(main
.player
, subject
, this))
137 override public function getScreenText
():String
150 public class ShopScreen extends Screen
153 override public function getScreenText():String
158 override public function processButtonPress(id:int):Boolean
161 var item:Item = null;
163 text = "<h2>Shop</h2>";
164 text += town.onShopWelcome();
165 setButton(0, "EXIT");
167 setButton(2, "Sell");
170 case -1: return false; break;
175 return processButtonPress( -1);
178 return processButtonPress( -1);
182 text = "<h2>Buy</h2>";
183 text += town.onShopBuyMenu();
185 setButton(0, "BACK");
186 for (var i:int = 0; i < inventory.length; i++) {
187 // 2x WhiteBerry (15G)
189 text += "<li><b>" + item.amount + "x " + item.name + " (" + (item.value + tax) + "G)</b> - <i>" + item.descr + "</i></li>";
190 setButton(i + 1, item.name);
196 return processButtonPress( -1);
199 item = Item.findByID((inventory[id - 1] as Item).id);
200 var price:int = (item.value + tax);
201 // Check if we have enough money
202 if (main.player.gold - price < 0) {
203 text = "You don't have enough money for this.";
208 (inventory[id - 1] as Item).amount--;
209 if ((inventory[id - 1] as Item).amount == 0) {
210 inventory.splice(id - 1, 1);
215 main.player.addToInventory(item);
216 main.player.gold -= price;
225 text = "<h2>Sell</h2>";
226 text += town.onShopSellMenu();
227 setButton(0, "BACK");
228 if(inventory.length>0) {
230 for (i = 0; i < main.player.inventory.length; i++) {
231 // 2x WhiteBerry (15G)
232 item = main.player.inventory[i];
233 text += "<li><b>" + item.amount + "x " + item.name + " (" + (item.value - tax) + "G)</b> - <i>" + item.descr + "</i></li>";
234 setButton(i + 1, item.name);
238 text += "<p><i>You have nothing to sell.</i></p>";
243 return processButtonPress( -1);
246 item = main.player.inventory[id - 1]
247 trace("SHOPSCREEN ITEM",item);
250 price = (item.value - tax);
252 main.player.takeFromInventory(item);
253 main.player.gold += price;