//        [Test]
        /// <summary>
        /// Test correct behaviour occurs when the asset owner does not own the sitting parcel water rights
        /// </summary>
        public void TestAssetParcelWaterRightsNotOwned()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 10 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable = 18, WaterRightsOwner = p1 };
            BuyPoint bp3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000030")) { WaterAvailable = 14, WaterRightsOwner = p1 };
            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1") { BuyPoint = bp1 };
            Houses h1 = new Houses("Houses", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 20, Field = f1 };
            bp1.AddGameAsset(h1);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(18));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(14));
            Assert.That(p1.Water, Is.EqualTo(32));

            allocator.ChangeAllocation(h1, p1, h1.WaterUsage);

            Assert.That(h1.WaterAllocated, Is.EqualTo(20));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(20));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(0));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(12));
            Assert.That(p1.Water, Is.EqualTo(12));
        }
Ejemplo n.º 2
0
        public BuyPoint CreateBuyPoint(UUID uuid, string name, Vector3 pos, ILandObject osParcel, RegionInfo regionInfo)
        {
            BuyPoint bp = new BuyPoint(uuid, name, pos, osParcel) { Game = m_controller.Game };
            bp.Location.RegionName = regionInfo.RegionName;
            bp.Location.RegionId = regionInfo.RegionID;
            bp.Location.RegionX = regionInfo.RegionLocX;
            bp.Location.RegionY = regionInfo.RegionLocY;

            return bp;
        }
        public AskLandBuyerInteraction(
            WaterWarsController controller, HudView playerHud, HudView targetPlayerHud, BuyPoint bp, 
            int salePrice, RightsType rightsToSell)
            : base(controller, playerHud, targetPlayerHud)
        {
            m_bp = bp;
            if (!m_controller.Game.Players.TryGetValue(playerHud.UserId, out m_p)) return;
            if (!m_controller.Game.Players.TryGetValue(targetPlayerHud.UserId, out m_targetPlayer)) return;
            m_salePrice = salePrice;
            m_rightsToSell = rightsToSell;

            AskBuyer();
        }
        public void TestGenerationBelowEntitlement()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000011")) { InitialWaterRights = 100 };
            List<BuyPoint> buyPoints = new List<BuyPoint> { bp1 };

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001")) { WaterEntitlement = 300 };
            Player p2 = new Player("Betty", UUID.Parse("00000000-0000-0000-0000-000000000002")) { WaterEntitlement = 200 };
            List<Player> players = new List<Player> { p1, p2 };

            Dictionary<Player, int> allocation = distributor.Allocate(300, players, buyPoints);

            Assert.That(allocation[p1], Is.EqualTo(150));
            Assert.That(allocation[p2], Is.EqualTo(100));
        }
Ejemplo n.º 5
0
        /// <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 void TestMultiTiersUnderAllocation()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            int water = 2600;

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            Player p2 = new Player("Betty", UUID.Parse("00000000-0000-0000-0000-000000000002"));
            List<Player> players = new List<Player> { p1, p2 };

            BuyPoint bp1_1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterRightsOwner = p1 };
            bp1_1.Location.LocalPosition = new Vector3(10, 80, 10);
            BuyPoint bp1_2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) {  WaterRightsOwner = p2 };
            bp1_2.Location.LocalPosition = new Vector3(30, 70, 20);

            BuyPoint bp2_1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000030")) { WaterRightsOwner = p1 };
            bp2_1.Location.LocalPosition = new Vector3(05, 35, 20);
            BuyPoint bp2_2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000040")) { WaterRightsOwner = p2 };
            bp2_2.Location.LocalPosition = new Vector3(10, 25, 20);
            BuyPoint bp2_3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000050")) { WaterRightsOwner = p1 };
            bp2_3.Location.LocalPosition = new Vector3(30, 27, 20);

            List<BuyPoint> buyPoints = new List<BuyPoint> { bp1_1, bp1_2, bp2_1, bp2_2, bp2_3 };

            Dictionary<Player, int> allocation = distributor.Allocate(water, players, buyPoints);

            int firstTierParcelsGet = TestParcelWaterEntitlement;
            int secondTierParcelsGet = (water - TestParcelWaterEntitlement * 2) / 3;
            Assert.That(allocation[p1], Is.EqualTo(firstTierParcelsGet + secondTierParcelsGet * 2));
            Assert.That(allocation[p2], Is.EqualTo(firstTierParcelsGet + secondTierParcelsGet));

            Assert.That(bp1_1.WaterAvailable, Is.EqualTo(firstTierParcelsGet));
            Assert.That(bp1_2.WaterAvailable, Is.EqualTo(firstTierParcelsGet));

            Assert.That(bp2_1.WaterAvailable, Is.EqualTo(secondTierParcelsGet));
            Assert.That(bp2_2.WaterAvailable, Is.EqualTo(secondTierParcelsGet));
            Assert.That(bp2_3.WaterAvailable, Is.EqualTo(secondTierParcelsGet));
        }
        public void TestGenerationAboveEntitlement()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            int parcelWaterEntitlement = 1000;

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            Player p2 = new Player("Betty", UUID.Parse("00000000-0000-0000-0000-000000000002"));
            List<Player> players = new List<Player> { p1, p2 };

            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000011"))
                { InitialWaterRights = parcelWaterEntitlement, WaterRightsOwner = p1 };
            bp1.Location.LocalPosition = new Vector3(10, 30, 10);

            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000012"))
                { InitialWaterRights = parcelWaterEntitlement, WaterRightsOwner = p2 };
            bp2.Location.LocalPosition = new Vector3(30, 30, 20);

            BuyPoint bp3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000013"))
                { InitialWaterRights = parcelWaterEntitlement, WaterRightsOwner = p1 };
            bp3.Location.LocalPosition = new Vector3(50, 30, 20);

            BuyPoint bp4 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000014"));
            bp4.Location.LocalPosition = new Vector3(52, 30, 30);

            List<BuyPoint> buyPoints = new List<BuyPoint> { bp1, bp2, bp3, bp4 };

            Dictionary<Player, int> allocation = distributor.Allocate(4000, players, buyPoints);

            int eachParcelGets = parcelWaterEntitlement;
            Assert.That(allocation[p1], Is.EqualTo(eachParcelGets * 2));
            Assert.That(allocation[p2], Is.EqualTo(eachParcelGets));

            Assert.That(bp1.WaterAvailable, Is.EqualTo(eachParcelGets));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(eachParcelGets));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(eachParcelGets));
            Assert.That(bp4.WaterAvailable, Is.EqualTo(0));
        }
Ejemplo n.º 8
0
        public void TestBuyPoint()
        {
            TestHelpers.InMethod();

            // The field class has already constructed Field.None, which conceptually belongs to BuyPoint.None
            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(1));

            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1");

            // Both f1 and Field.None are attached to BuyPoint.None at this point
            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(2));
            Assert.That(f1.BuyPoint, Is.EqualTo(BuyPoint.None));

            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010"));
            Assert.That(bp1.Fields.Count, Is.EqualTo(0));
            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(2));

            f1.BuyPoint = bp1;

            Assert.That(BuyPoint.None.Fields.Count, Is.EqualTo(1));
            Assert.That(bp1.Fields.Count, Is.EqualTo(1));
            Assert.That(f1.BuyPoint, Is.EqualTo(bp1));
        }
Ejemplo n.º 9
0
        public BuyPointView(WaterWarsController controller, Scene scene, AbstractView itemStoreView, BuyPoint bp)
            : base(controller, scene, itemStoreView)
        {
            m_bp = bp;
            m_bp.OnChange += Update;

            m_veSceneObjectNames[AbstractGameAssetType.None] = "For Sale";
            m_veSceneObjectNames[AbstractGameAssetType.Crops] = "Farmhouse";
            m_veSceneObjectNames[AbstractGameAssetType.Houses] = "Site Office";
            m_veSceneObjectNames[AbstractGameAssetType.Factory] = "Portacabin";
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Sell rights for a particular parcel
        /// </summary>
        /// <param name="bp"></param>
        /// <param name="buyerId"></param>
        /// <param name="rightsType"></param>
        /// <param name="price"></param>
        public void SellRights(BuyPoint bp, UUID buyerId, RightsType rightsType, int price)
        {
            Player buyer = GetPlayer(buyerId);
            Player sellingPlayer = null;

            if (rightsType == RightsType.Water)
                sellingPlayer = bp.WaterRightsOwner;
            else
                sellingPlayer = bp.DevelopmentRightsOwner;

            m_log.InfoFormat(
                "[WATER WARS]: Starting process of player {0} selling {1} rights on {2} to {3} for {4}",
                sellingPlayer.Name, rightsType, bp.Name, buyer.Name, price);

            if (m_controller.AttachedToVe)
                new AskLandBuyerInteraction(
                    m_controller,
                    m_controller.HudManager.m_playerIdToHud[sellingPlayer.Uuid],
                    m_controller.HudManager.m_playerIdToHud[buyer.Uuid],
                    bp,
                    price,
                    rightsType);
            else
                m_controller.State.SellRights(bp, buyer, rightsType, price);
        }
Ejemplo n.º 11
0
 public override void ChangeBuyPointName(BuyPoint bp, string newName)
 {
     bp.Name = newName;
     bp.TriggerChanged();
 }
Ejemplo n.º 12
0
 public Field GetField(BuyPoint bp, string rawUuid)
 {
     return GetField(bp, WaterWarsUtils.ParseRawId(rawUuid));
 }
Ejemplo n.º 13
0
 public Field GetField(BuyPoint bp, UUID uuid)
 {
     lock (bp.Fields)
     {
         if (!bp.Fields.ContainsKey(uuid))
             throw new Exception(string.Format("Field with id {0} in buypoint {1} does not exist", uuid, bp.Name));
         else
             return bp.Fields[uuid];
     }
 }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
 public AbstractGameAsset GetAsset(BuyPoint bp, UUID uuid)
 {
     lock (bp.GameAssets)
     {
         if (!bp.GameAssets.ContainsKey(uuid))
             throw new Exception(string.Format("Game asset with id {0} in buypoint {1} does not exist", uuid, bp.Name));
         else
             return bp.GameAssets[uuid];
     }
 }
Ejemplo n.º 16
0
 public void TriggerOnBuyPointNameChanged(BuyPoint bp)
 {
     if (OnBuyPointNameChanged != null)
         OnBuyPointNameChanged(bp);
 }
Ejemplo n.º 17
0
        protected Hashtable HandleBuyRights(
            BuyPoint bp, bool buyingDevelopmentRights, bool buyingWaterRights,
            string rawDevelopmentRightsBuyerId, string rawWaterRightsBuyerId,
            int? developmentRightsPrice, int? waterRightsPrice, int? combinedRightsPrice, Hashtable request)
        {
            if (bp.DevelopmentRightsOwner == Player.None)
            {
                m_controller.Resolver.BuyLandRights(bp.Uuid.ToString(), rawDevelopmentRightsBuyerId);
            }
            else
            {
                UUID developmentRightsBuyerId = UUID.Zero;
                if (rawDevelopmentRightsBuyerId != null)
                    developmentRightsBuyerId = WaterWarsUtils.ParseRawId(rawDevelopmentRightsBuyerId);

                UUID waterRightsBuyerId = UUID.Zero;
                if (rawWaterRightsBuyerId != null)
                    waterRightsBuyerId = WaterWarsUtils.ParseRawId(rawWaterRightsBuyerId);

                // TODO: Do player ownership checks later when we have access to this via security

                if (buyingDevelopmentRights && buyingWaterRights)
                {
                    if (null == combinedRightsPrice)
                        throw new Exception(
                            string.Format("No combined rights price specified for sale of {0} rights", bp));

                    m_controller.Resolver.SellRights(
                        bp, developmentRightsBuyerId, RightsType.Combined, (int)combinedRightsPrice);
                }
                else if (buyingDevelopmentRights)
                {
                    if (null == developmentRightsPrice)
                        throw new Exception(
                            string.Format("No development rights price specified for sale of {0} rights", bp));

                    m_controller.Resolver.SellRights(
                        bp, developmentRightsBuyerId, RightsType.Development, (int)developmentRightsPrice);
                }
                else if (buyingWaterRights)
                {
                    if (null == waterRightsPrice)
                        throw new Exception(
                            string.Format("No water rights price specified for sale of {0} rights", bp));

                    m_controller.Resolver.SellRights(
                        bp, waterRightsBuyerId, RightsType.Water, (int)waterRightsPrice);
                }
            }

            // TODO: Deal with error situations: uuid not valid, no such buy point, not enough money, etc.

            Hashtable reply = new Hashtable();
            reply["int_response_code"] = 200; // 200 OK
            reply["str_response_string"] = "hoorah";
            reply["content_type"] = "text/plain";

            return reply;
        }
Ejemplo n.º 18
0
 public void TriggerLandRightsGiven(BuyPoint bp)
 {
     if (OnLandRightsGiven != null)
         OnLandRightsGiven(bp);
 }
Ejemplo n.º 19
0
 public void TriggerBuyPointRegistered(BuyPoint bp)
 {
     if (OnBuyPointRegistered != null)
         OnBuyPointRegistered(bp);
 }
Ejemplo n.º 20
0
 public void Initialize(BuyPoint bp)
 {
     m_bp = bp;
 }
Ejemplo n.º 21
0
 public Field CreateField(BuyPoint bp, UUID uuid, string name)
 {
     return new Field(uuid, name) { BuyPoint = bp, Owner = bp.DevelopmentRightsOwner, Game = m_controller.Game };
 }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
 public void TriggerLandRightsBought(BuyPoint bp, Player p)
 {
     if (OnLandRightsBought != null)
         OnLandRightsBought(bp, p);
 }
Ejemplo n.º 24
0
        public string FetchBuyPointConfiguration(BuyPoint bp)
        {
            lock (m_buyPointViews)
            {
                if (m_buyPointViews.ContainsKey(bp.Uuid))
                    return m_buyPointViews[bp.Uuid].FetchConfiguration();
            }

            return null;
        }
Ejemplo n.º 25
0
 public void TriggerLandRightsSold(BuyPoint bp, Player buyer, Player seller, RightsType type, int salePrice, bool success)
 {
     if (OnLandRightsSold != null)
         OnLandRightsSold(bp, buyer, seller, type, salePrice, success);
 }
Ejemplo n.º 26
0
 public void RemoveBuyPointView(BuyPoint bp)
 {
     lock (m_buyPointViews)
         GetBuyPointView(bp.Uuid).Close();
 }
Ejemplo n.º 27
0
 public static string SerializeBuyPoint(BuyPoint bp)
 {
     return JsonConvert.SerializeObject(bp, Formatting.Indented);
 }
Ejemplo n.º 28
0
        public Dictionary<UUID, Field> ChangeBuyPointSpecialization(
             BuyPoint bp, AbstractGameAssetType type, int numberOfFields)
        {
            Dictionary<UUID, Field> fields = new Dictionary<UUID, Field>();
            for (int i = 1; i <= numberOfFields; i++)
            {
                Field f = m_controller.ModelFactory.CreateField(bp, UUID.Random(), string.Format("Field {0}", i));
                fields[f.Uuid] = f;
            }

            lock (m_buyPointViews)
                GetBuyPointView(bp.Uuid).ChangeSpecialization(type, fields.Values.ToList());

            return fields;
        }
Ejemplo n.º 29
0
        protected Hashtable HandleChangeName(BuyPoint bp, string newName)
        {
            m_controller.State.ChangeBuyPointName(bp, newName);

            Hashtable reply = new Hashtable();
            reply["int_response_code"] = 200; // 200 OK
            reply["str_response_string"] = "sausages";
            reply["content_type"] = "text/plain";

            return reply;
        }
Ejemplo n.º 30
0
 public AbstractGameAsset GetAsset(BuyPoint bp, string rawUuid)
 {
     return GetAsset(bp, WaterWarsUtils.ParseRawId(rawUuid));
 }