示例#1
0
        public override void SellRights(BuyPoint bp, Player buyer, RightsType type, int salePrice)
        {
            Player seller = Player.None;

            if (type == RightsType.Development || type == RightsType.Combined)
                seller = bp.DevelopmentRightsOwner;
            else
                seller = bp.WaterRightsOwner;

            if (!bp.OwnerActions.ContainsKey("SellDevelopmentRights"))
                throw new WaterWarsGameLogicException(
                    "Player {0} tried to sell development rights on {1} in {2} but they have already sold game assets to the economy on this parcel",
                    seller.Name, bp.Name, bp.Location.RegionName);

            if (buyer.Money < salePrice)
                throw new WaterWarsGameLogicException(
                    "Player {0} tried to buy {1} rights for {2} from {3} for {4} but they only have {5}",
                    buyer, type, bp, seller, salePrice, buyer.Money);

            m_log.InfoFormat(
                "[WATER WARS]: Player {0} selling {1} rights of {2} to {3} for {4}",
                seller, type, bp, buyer, salePrice);

            // Perform the transaction
            if (type == RightsType.Water || type == RightsType.Combined)
                bp.WaterRightsOwner = buyer;

            buyer.Money -= salePrice;
            buyer.LandCostsThisTurn += salePrice;
            seller.Money += salePrice;
            seller.LandRevenueThisTurn += salePrice;

            // If we're selling development rights then we also need to remove any game assets already on the parcel
            if (type == RightsType.Development || type == RightsType.Combined)
            {
                lock (bp.GameAssets)
                {
                    foreach (AbstractGameAsset asset in bp.GameAssets.Values)
                        m_controller.Dispatcher.RemoveGameAssetView(asset);
                }

                bp.RemoveAllGameAssets();
            }

            if (type == RightsType.Development || type == RightsType.Combined)
                TransferDevelopmentRights(bp, buyer);

            m_controller.EventManager.TriggerLandRightsSold(bp, buyer, seller, type, salePrice, true);
            buyer.TriggerChanged();
            seller.TriggerChanged();
            bp.TriggerChanged();

            // FIXME: Should be done via event subscription.
            UpdateHudStatus(buyer);
            UpdateHudStatus(seller);

            m_controller.Events.PostToAll(
                string.Format(SELL_RIGHTS_CRAWL_MSG, seller.Name, type, bp.Name, bp.Location.RegionName, buyer.Name),
                EventLevel.Crawl);
        }