/// <summary> /// Sell water available on a particular parcel /// </summary> /// <param name="sellerId"></param> /// <param name="buyerId"></param> /// <param name="amount"></param> /// <param name="price"></param> public void SellWater(UUID sellerId, UUID buyerId, int amount, int price) { Player buyer = GetPlayer(buyerId); Player seller = GetPlayer(sellerId); if (m_controller.AttachedToVe) { if (amount > seller.Water) { // A messy abstraction breaking hack to alert the player that they can't go ahead. m_controller.HudManager.m_playerIdToHud[seller.Uuid].m_statusButton.SendAlert( seller.Uuid, string.Format( "Can't sell {0} to {1} since you only have {2}", WaterWarsUtils.GetWaterUnitsText(amount), buyer.Name, WaterWarsUtils.GetWaterUnitsText(seller.Water))); } else { new AskWaterBuyerInteraction( m_controller, m_controller.HudManager.m_playerIdToHud[seller.Uuid], m_controller.HudManager.m_playerIdToHud[buyer.Uuid], amount, price); } } else { m_controller.State.SellWater(seller, buyer, amount, price); } }
/// <summary> /// Use available water on a particular asset on a particular parcel /// </summary> /// <param name="rawBuyPointId"></param> /// <param name="rawAssetId"></param> /// <param name="rawPlayerId">Temporarily, this can be UUID.Zero if no player id was supplied in the request</param> /// <param name="amount"> /// Amount of water to use. If this is zero and there already is some water allocated then this signals undo /// </param> public void UseWater(string rawBuyPointId, string rawAssetId, string rawPlayerId, int amount) { UUID buyPointId = WaterWarsUtils.ParseRawId(rawBuyPointId); UUID assetId = WaterWarsUtils.ParseRawId(rawAssetId); UUID playerId = WaterWarsUtils.ParseRawId(rawPlayerId); BuyPoint bp = GetBuyPoint(buyPointId); AbstractGameAsset a = GetAsset(bp, assetId); if (0 == amount) { m_controller.State.UndoUseWater(a); } else { Player p = null; if (playerId != UUID.Zero) { p = GetPlayer(playerId); } else { p = bp.DevelopmentRightsOwner; } m_controller.State.UseWater(a, p, amount); } }
/// <summary> /// Buy water and development rights for a particular parcel /// </summary> /// <param name="rawBuyPointId"></param> /// <param name="rawPlayerId"></param> public void BuyLandRights(string rawBuyPointId, string rawPlayerId) { UUID playerId = WaterWarsUtils.ParseRawId(rawPlayerId); Player buyer = GetPlayer(playerId); UUID buyPointId = WaterWarsUtils.ParseRawId(rawBuyPointId); BuyPoint bp = GetBuyPoint(buyPointId); if (buyer.Money < bp.CombinedPrice) { // A messy abstraction breaking hack to alert the player that they can't go ahead. m_controller.HudManager.m_playerIdToHud[buyer.Uuid].m_statusButton.SendAlert( buyer.Uuid, string.Format( "Can't buy rights because they cost {0}{1} and you only have {2}{3}", WaterWarsConstants.MONEY_UNIT, bp.CombinedPrice, WaterWarsConstants.MONEY_UNIT, buyer.Money)); } else { m_controller.State.BuyLandRights(bp, buyer); } }
/// <summary> /// Sell a game asset to the economy /// </summary> /// <param name="rawBuyPointId"></param> /// <param name="rawGameAssetId"></param> public void SellGameAssetToEconomy(string rawBuyPointId, string rawGameAssetId) { UUID buyPointId = WaterWarsUtils.ParseRawId(rawBuyPointId); UUID gameAssetId = WaterWarsUtils.ParseRawId(rawGameAssetId); BuyPoint bp = GetBuyPoint(buyPointId); AbstractGameAsset ga = GetAsset(bp, gameAssetId); m_controller.State.SellGameAssetToEconomy(ga); }
/// <summary> /// Remove a particular game asset on a parcel /// </summary> /// <param name="buyPointId"></param> /// <param name="rawGameAssetId"> public Field RemoveGameAsset(string rawBuyPointId, string rawGameAssetId) { UUID buyPointId = WaterWarsUtils.ParseRawId(rawBuyPointId); UUID gameAssetId = WaterWarsUtils.ParseRawId(rawGameAssetId); BuyPoint bp = GetBuyPoint(buyPointId); AbstractGameAsset ga = GetAsset(bp, gameAssetId); return(m_controller.State.RemoveGameAsset(ga)); }
/// <summary> /// Upgrade a game asset. /// </summary> /// This is called by code which only has the ids available. /// <param name="rawBuyPointId"></param> /// <param name="rawPlayerId"></param> /// <param name="level"></param> public void UpgradeGameAsset(string rawBuyPointId, string rawAssetId, int level) { UUID buyPointId = WaterWarsUtils.ParseRawId(rawBuyPointId); BuyPoint bp = GetBuyPoint(buyPointId); UUID assetId = WaterWarsUtils.ParseRawId(rawAssetId); AbstractGameAsset asset = GetAsset(bp, assetId); m_controller.State.UpgradeGameAsset(bp.DevelopmentRightsOwner, asset, level); }
/// <summary> /// Buy a game asset. /// </summary> /// <param name="rawBuyPointId"></param> /// <param name="rawAssetId"></param> public AbstractGameAsset ContinueBuildingGameAsset(string rawBuyPointId, string rawAssetId) { UUID buyPointId = WaterWarsUtils.ParseRawId(rawBuyPointId); BuyPoint bp = GetBuyPoint(buyPointId); UUID assetId = WaterWarsUtils.ParseRawId(rawAssetId); AbstractGameAsset asset = GetAsset(bp, assetId); return(m_controller.State.ContinueBuildingGameAsset(asset)); }
/// <summary> /// Buy a game asset. /// </summary> /// This is called by code which only has the ids available. /// <param name="rawBuyPointId"></param> /// <param name="rawFieldId"></param> /// <param name="level"></param> public AbstractGameAsset BuildGameAsset(string rawBuyPointId, string rawFieldId, int level) { UUID buyPointId = WaterWarsUtils.ParseRawId(rawBuyPointId); UUID fieldId = WaterWarsUtils.ParseRawId(rawFieldId); BuyPoint bp = GetBuyPoint(buyPointId); Field f = GetField(bp, fieldId); Player p = bp.DevelopmentRightsOwner; return(BuildGameAsset(f, p.Role.AllowedAssets[0], level)); }
/// <summary> /// Add a player /// </summary> /// <param name="rawPlayerId"></param> /// <param name="roleType"></param> /// <returns>Player added</returns> public Player AddPlayer(string rawPlayerId, RoleType roleType) { IRole role = null; switch (roleType) { case RoleType.Developer: role = Developer.Singleton; break; case RoleType.Farmer: role = Farmer.Singleton; break; case RoleType.Manufacturer: role = Manufacturer.Singleton; break; case RoleType.WaterMaster: role = WaterMaster.Singleton; break; } UUID playerId = WaterWarsUtils.ParseRawId(rawPlayerId); ScenePresence scenePresence = null; // Look for the presence in every scene. If this kind of thing becomes common we will need to refactor the // code foreach (Scene scene in m_controller.Scenes) { ScenePresence sp = scene.GetScenePresence(playerId); if (sp != null) { scenePresence = sp; break; } } if (null == scenePresence) { throw new Exception( string.Format( "ScenePresence unexpectedly null for player {0} registering for role {1}", playerId, roleType)); } Player newPlayer = m_controller.ModelFactory.CreatePlayer(scenePresence.UUID, scenePresence.Name, role); m_controller.State.AddPlayer(newPlayer); return(newPlayer); }
/// <summary> /// Request water from other players /// </summary> /// <param name="requesterId"></param> /// <param name="amount"></param> public void RequestWater(UUID requesterId, int amount) { Player requester = GetPlayer(requesterId); m_log.InfoFormat( "[WATER WARS]: Starting process of player {0} requesting {1} water", requester.Name, amount); m_controller.Events.PostToAll( string.Format("{0} would like to lease {1}", requester.Name, WaterWarsUtils.GetWaterUnitsText(amount)), EventLevel.Alert); }
/// <summary> /// Add plinths to the given scene. /// </summary> /// <param name="scene"></param> public void AddPlinths(Scene scene) { List <ILandObject> parcels = scene.LandChannel.AllParcels(); // We want to place the plinth a little back from the corner Vector3 rezAdjustment = new Vector3(-4, -4, 0); foreach (ILandObject lo in parcels) { Vector3 swPoint, nePoint; WaterWarsUtils.FindSquareParcelCorners(lo, out swPoint, out nePoint); Vector3 rezPoint = nePoint + rezAdjustment; //BuyPoint bp = Resolver.RegisterBuyPoint(State, so); m_controller.GameManagerView.CreateBuyPointView(scene, rezPoint); // Dispatcher.RegisterBuyPointView(bpv); // State.UpdateBuyPointStatus(bp); } }
public Field GetField(BuyPoint bp, string rawUuid) { return(GetField(bp, WaterWarsUtils.ParseRawId(rawUuid))); }
public AbstractGameAsset GetAsset(BuyPoint bp, string rawUuid) { return(GetAsset(bp, WaterWarsUtils.ParseRawId(rawUuid))); }
public Player GetPlayer(string rawUuid) { return(GetPlayer(WaterWarsUtils.ParseRawId(rawUuid))); }
public BuyPoint GetBuyPoint(string rawUuid) { return(GetBuyPoint(WaterWarsUtils.ParseRawId(rawUuid))); }
/// <summary> /// Make the terrain for all game parcels completely level. /// </summary> /// <param name="scene"></param> /// <param name="raise">Raise the land? If this is false then we are lowering</param> public void LevelGameParcels(Scene scene, bool raise) { List <BuyPoint> buyPoints; lock (m_controller.Game.BuyPoints) buyPoints = m_controller.Game.BuyPoints.Values.ToList(); m_log.InfoFormat("[WATER WARS]: Leveling parcels in {0}", scene.RegionInfo.RegionName); foreach (BuyPoint bp in buyPoints) { ILandObject lo = bp.Location.Parcel; if (lo.RegionUUID != scene.RegionInfo.RegionID) { continue; } Vector3 swPoint, nePoint; WaterWarsUtils.FindSquareParcelCorners(lo, out swPoint, out nePoint); Vector3 refHeightPoint; if (raise) { refHeightPoint = new Vector3(0, 0, 0); } else { refHeightPoint = new Vector3(0, 0, 255); } for (int x = (int)Math.Floor(swPoint.X); x <= (int)Math.Floor(nePoint.X); x++) { for (int y = (int)Math.Floor(swPoint.Y); y <= (int)Math.Floor(nePoint.Y); y++) { float height = (float)scene.Heightmap[x, y]; if (raise) { if (height > refHeightPoint.Z) { refHeightPoint = new Vector3(x, y, height); } } else { if (height < refHeightPoint.Z) { refHeightPoint = new Vector3(x, y, height); } } } } m_log.InfoFormat( "[WATER WARS]: Found {0} height point for parcel ({1},{2}) at {3}", (raise ? "max" : "min"), nePoint, swPoint, refHeightPoint); //refHeightPoint.Z = (float)Math.Ceiling(refHeightPoint.Z); m_log.InfoFormat( "[WATER WARS]: Setting all terrain on parcel ({0},{1}) to {2}", nePoint, swPoint, refHeightPoint.Z); for (int x = (int)Math.Floor(swPoint.X); x <= (int)Math.Floor(nePoint.X); x++) { for (int y = (int)Math.Floor(swPoint.Y); y <= (int)Math.Floor(nePoint.Y); y++) { scene.Heightmap[x, y] = refHeightPoint.Z; } } } ITerrainModule terrainModule = scene.RequestModuleInterface <ITerrainModule>(); terrainModule.TaintTerrain(); }