Ejemplo n.º 1
0
        internal item SellItemNormal(unit shop, HabProperties hpsItem)
        {
            string  ID   = hpsItem.name;
            IRecord item = Items.GetByUnit("codeID", ID);

            bool isNewVersionItem = DHHELPER.IsNewVersionItem(ID);

            if (!(item is item) && !(item is unit))
            {
                item = isNewVersionItem ? (IRecord) new unit(hpsItem.name) : (IRecord) new item(hpsItem.name);
                Items.Add(item);
            }

            item = item.Clone();

            if (isNewVersionItem)
            {
                (item as unit).DoSummon = true;
                (item as unit).set_owningPlayer(Current.unit.get_owningPlayer()); //!

                shop.OnSell(item as unit);                                        // sell item as unit
            }
            else
            {
                shop.OnSellItem(item as item, Current.unit);
            }

            // pay the gold for this item

            int goldCost = isNewVersionItem ? (item as unit).goldCost : (item as item).goldCost;

            Current.player.Gold = Current.player.Gold - goldCost;

            return(item as item);
        }
Ejemplo n.º 2
0
        internal unit SellHero(HabProperties hps)
        {
            if (hps == null)
            {
                return(null);
            }

            string ID   = hps.GetStringValue("Name");
            unit   hero = Heroes.GetByUnit("ID", ID) as unit;

            if (hero != null && hero.IsDisposed)
            {
                if (Current.unit != null && Current.unit != hero &&
                    Current.unit.codeID == hero.codeID &&
                    !Current.unit.IsDisposed)
                {
                    Heroes.Remove(hero);
                    Heroes.Add(Current.unit);
                    hero = Current.unit;
                }
                else
                {
                    Heroes.Remove(hero);
                    hero = null;
                }
            }

            if (hero == null)
            {
                unit sellingTavern = null;

                // find the tavern that sold this hero

                string tavernID = DHLOOKUP.dcHeroesTaverns[hps.name];
                foreach (unit tavern in DHLOOKUP.taverns)
                {
                    if (tavern.ID == tavernID)
                    {
                        sellingTavern = tavern;
                    }
                }

                // create new hero

                hero          = new unit(hps.name);
                hero.DoSummon = true;
                hero.set_owningPlayer(Current.player, sellingTavern.x, sellingTavern.y);
                Heroes.Add(hero);

                // only new heroes process onsell event

                sellingTavern.OnSell(hero);

                // pay the gold for this hero

                Current.player.Gold = Current.player.Gold - hero.goldCost;
            }

            return(hero);
        }