/// <summary> /// Refactor with common parts of parcel purchase /// </summary> /// <param name="bp"></param> /// <param name="owner"></param> public void AllocateParcel(BuyPoint bp, Player owner) { TransferAllRights(bp, owner); owner.TriggerChanged(); bp.TriggerChanged(); // TODO: This should really be a transfer event - since they weren't 'bought' m_controller.EventManager.TriggerLandRightsGiven(bp); // FIXME: This should be done via events UpdateHudStatus(owner); // m_controller.Events.PostToAll( // string.Format(BUY_RIGHTS_CRAWL_MSG, buyer.Name, bp.Name, bp.RegionName), // EventLevel.Crawl); }
public override void ChangeBuyPointName(BuyPoint bp, string newName) { bp.Name = newName; bp.TriggerChanged(); }
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); }
public override void BuyLandRights(BuyPoint bp, Player buyer) { if (bp.DevelopmentRightsOwner != Player.None) throw new WaterWarsGameLogicException( string.Format( "[WATER WARS]: {0} tried to buy parcel {1} but development rights are already owned by {2}", buyer, bp, bp.DevelopmentRightsOwner)); if (bp.WaterRightsOwner != Player.None) throw new WaterWarsGameLogicException( string.Format( "[WATER WARS]: {0} tried to buy parcel {1} but water rights are already owned by {2}", buyer, bp, bp.WaterRightsOwner)); if (buyer.Money < bp.CombinedPrice) // TODO: Signal this to the player in-world in some way throw new WaterWarsGameLogicException( string.Format("[WATER WARS]: Player {0} didn't have enough money to buy {1}", buyer, bp)); m_log.InfoFormat("[WATER WARS]: Player {0} buying land rights for {1}", buyer, bp); buyer.Money -= bp.CombinedPrice; buyer.LandCostsThisTurn += bp.CombinedPrice; TransferAllRights(bp, buyer); buyer.TriggerChanged(); bp.TriggerChanged(); m_controller.EventManager.TriggerLandRightsBought(bp, buyer); // FIXME: This should be done via events UpdateHudStatus(buyer); m_controller.Events.PostToAll( string.Format(BUY_RIGHTS_CRAWL_MSG, buyer.Name, bp.Name, bp.Location.RegionName), EventLevel.Crawl); }