Fix hair, dick around with new game screen.
[18plus-7leafadventure.git] / src / org / sevenchan / dongs / screens / Shop.as
blobf6db49715e0888ec8b3fc56dbe7b5a2a90432e11
1 package org.sevenchan.dongs.screens
3 import org.sevenchan.dongs.Item;
4 import org.sevenchan.dongs.Screen;
5 import org.sevenchan.dongs.Town;
6 import flash.utils.*;
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;
20 /**
21 * ...
22 * @author Harbinger
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;
42 this.name = name;
43 this.town = t;
44 this.markup = markup;
45 super(null);
46 this.name = name;
47 inventory = [];
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);
57 return true;
58 }, 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);
72 return true;
73 }, item);
77 override public function processButtonPress(id:int):Boolean
79 clearButtons();
80 if (abort)
82 return true;
84 text = currentItem.content;
85 switch (id)
88 case-1:
89 onStartupScreen();
90 appendMenu();
91 updateScreen();
92 updateSellMenu();
93 return false;
94 break;
95 case 0:
96 if (currentItem.parent == null)
98 onLeaving();
99 return true;
101 else
103 currentItem = currentItem.parent;
104 appendMenu();
105 updateScreen();
106 updateSellMenu();
107 return false;
109 break;
110 default:
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);
117 else
119 if ((MenuNode(nci)).canSwitchTo(main.player, subject, this))
121 currentItem = nci;
124 if (!abort)
125 text = nci.content;
126 if (!ret && !abort)
128 appendMenu();
130 updateScreen();
131 updateSellMenu();
132 return ret;
134 return false;
137 override public function getScreenText():String
139 return text;
146 * ...
147 * @author Harbinger
150 public class ShopScreen extends Screen
153 override public function getScreenText():String
155 return text;
158 override public function processButtonPress(id:int):Boolean
160 clearButtons();
161 var item:Item = null;
162 if (act == "main") {
163 text = "<h2>Shop</h2>";
164 text += town.onShopWelcome();
165 setButton(0, "EXIT");
166 setButton(1, "Buy");
167 setButton(2, "Sell");
168 updateScreen();
169 switch(id) {
170 case -1: return false; break;
171 case 0:
172 return true;
173 case 1:
174 act = "buy";
175 return processButtonPress( -1);
176 case 2:
177 act = "sell";
178 return processButtonPress( -1);
181 if (act == "buy") {
182 text = "<h2>Buy</h2>";
183 text += town.onShopBuyMenu();
184 text += "<ul>";
185 setButton(0, "BACK");
186 for (var i:int = 0; i < inventory.length; i++) {
187 // 2x WhiteBerry (15G)
188 item = inventory[i];
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);
192 text += "</ul>";
194 if (id == 0) {
195 act = "main";
196 return processButtonPress( -1);
198 if (id > 0) {
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.";
204 updateScreen();
205 return false;
207 // Deduct from store
208 (inventory[id - 1] as Item).amount--;
209 if ((inventory[id - 1] as Item).amount == 0) {
210 inventory.splice(id - 1, 1);
213 // Give to player
214 item.amount = 1;
215 main.player.addToInventory(item);
216 main.player.gold -= price;
217 main.refreshStats();
218 updateScreen();
219 return false;
221 updateScreen();
222 return false;
224 if (act == "sell") {
225 text = "<h2>Sell</h2>";
226 text += town.onShopSellMenu();
227 setButton(0, "BACK");
228 if(inventory.length>0) {
229 text += "<ul>";
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);
236 text += "</ul>";
237 } else {
238 text += "<p><i>You have nothing to sell.</i></p>";
241 if (id == 0) {
242 act = "main";
243 return processButtonPress( -1);
245 if (id > 0) {
246 item = main.player.inventory[id - 1]
247 trace("SHOPSCREEN ITEM",item);
248 if(item is Item) {
249 item=item.copy();
250 price = (item.value - tax);
251 item.amount = 1;
252 main.player.takeFromInventory(item);
253 main.player.gold += price;
254 main.refreshStats();
256 updateScreen();
257 return false;
259 updateScreen();
260 return false;
262 return false;