Example #1
0
        public int CalculateExperience(TradingPost destination)
        {
            // http://wiki.mabinogiworld.com/view/Commerce
            // floor(sqrt(Single Item Profit * Single Item Weight)) * Item Quantity * 30

            return(_slots.Sum(kvp =>
                              (int)(Math.Sqrt(kvp.Key.Profits.First(x => x.Destination == destination).Amount *kvp.Key.Weight)) * kvp.Value * 30));
        }
Example #2
0
        public void SubmitOffer()
        {
            Trader        me         = null;
            TradingPost   post       = null;
            Commodity     commondity = null;
            NewTradeOffer offer      = null;
            int           id         = 0;
            var           dbName     = "SubmitOffer";

            "Given I am a trader".x(async() =>
            {
                var traderRepository = new TraderRepository(CreateNewContext(dbName));
                id = await traderRepository.New(TestTradeDataStatic.MargamanTrader);
                me = await traderRepository.Get(id);
            });

            "And I have a trading post".x(async() =>
            {
                var systemRepository = new AstralSystemRepository(CreateNewContext(dbName));
                await systemRepository.New(TestSystemDataStatic.StantonSystem);
                var system = await systemRepository.Get(id);
                post       = system.TradePoints.OfType <TradingPost>().First();
            });

            "And I have a new commodity".x(async() =>
            {
                var commodityRepo = new CommodityRepository(CreateNewContext(dbName));
                var id            = await commodityRepo.New(TestTradeDataStatic.AgriciumCommondity);
                commondity        = await commodityRepo.Get(id);
            });

            "And I have an offer".x(() => offer = new NewTradeOffer
            {
                Id           = 0,
                TraderId     = me.Id,
                TradePointId = post.Id,
                CommodityId  = commondity.Id,
                PricePerUnit = 23.99M,
                OfferType    = (int)OfferType.Buy
            });

            "When I submit the offer".x(async() =>
            {
                var traderRepository = new TraderRepository(CreateNewContext(dbName));
                var command          = new NewTradeOfferCommand(traderRepository);
                id = await command.Execute(offer);
            });

            "Then the Offer is displayed".x(async() =>
            {
                var traderRepository = new TraderRepository(CreateNewContext(dbName), true);
                var trader           = await traderRepository.Get(me.Id);
                AssertOffer(trader.TradeOffers.First(o => o.Id == id), offer);
            });
        }
Example #3
0
 // Use this for initialization
 private void Awake()
 {
     tradingPost        = FindObjectOfType <TradingPost>();
     grid               = FindObjectOfType <Gridgenerator>();
     currentPos.x       = Random.Range(-15, 15);
     currentPos.y       = Random.Range(-15, 15);
     transform.position = currentPos;
     if (currentPos == grid.GetChaserPosition())
     {
         TakenReplace();
     }
 }
Example #4
0
    public bool BlockTradingpostSamePos(TradingPost tp)
    {
        if (blocks.Count > 0)
        {
            for (int i = 0; i < blocks.Count; i++)
            {
                if (tp.GetPostPosition() == blocks[i].GetBlockPosition())
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Example #5
0
    public Vector2 ClosestTile(TradingPost post)
    {
        closestTarget = Mathf.Infinity;
        for (int i = 0; i < tiles.Count; i++)
        {
            float distance = Vector2.Distance(post.transform.position, tiles[i].GetTilePosition());

            if (distance < closestTarget)
            {
                closestTarget = distance;
                closestTar    = tiles[i].GetTilePosition();
            }
        }
        return(closestTar);
    }
Example #6
0
        public Trade(Transportation transport, Route route, Load load, TradingPost source, TradingPost destination, List <Modifier> modifiers)
        {
            Destination = destination;
            Load        = load;
            Route       = route;
            Transport   = transport;
            Modifiers   = modifiers;

            BaseDuration   = TimeSpan.FromSeconds(route.Duration.TotalSeconds / Transport.SpeedFactor);
            BaseCost       = load.Slots.Sum(i => i.Key.Price * i.Value);
            BaseProfit     = BaseGold = BaseMerchantRating = load.CalculateProfit(destination);
            BaseExperience = load.CalculateExperience(destination);

            Cost           = BaseCost;
            Profit         = (int)(BaseProfit * (1 + modifiers.Sum(m => m.ProfitBonus)));
            Gold           = (int)(BaseGold * (1 + modifiers.Sum(m => m.GoldBonus)));
            MerchantRating = (int)(BaseMerchantRating * (1 + modifiers.Sum(m => m.MerchantRatingBonus)));
            Experience     = (int)(BaseExperience * (1 + modifiers.Sum(m => m.ExpBonus)));
            Duration       =
                TimeSpan.FromSeconds(route.Duration.TotalSeconds / (Transport.SpeedFactor + modifiers.Sum(m => m.SpeedBonus)));

            Gold           = Math.Max(0, Gold);
            MerchantRating = Math.Max(0, MerchantRating);
            Experience     = Math.Max(0, Experience);

            AddedCost           = Cost - BaseCost;
            AddedProfit         = Profit - BaseProfit;
            AddedGold           = Gold - BaseGold;
            AddedMerchantRating = MerchantRating - BaseMerchantRating;
            AddedExperience     = Experience - BaseExperience;
            AddedDuration       = Duration - BaseDuration;

            ProfitPerSecond = Profit / Duration.TotalSeconds;

            if (source.NoProfits.Contains(destination.Id))
            {
                Flags |= TradeFlags.NoProfit;
            }

            if (route.Path.Select(w => w.Target.Region).Any(r => r.ChokePoint))
            {
                Flags |= TradeFlags.ChokePoint;
            }

            ModifierNames = string.Join(", ", Modifiers.Select(m => m.Name));
        }
Example #7
0
        public Trade(Transportation transport, Route route, Load load, TradingPost source, TradingPost destination, List<Modifier> modifiers)
        {
            Destination = destination;
            Load = load;
            Route = route;
            Transport = transport;
            Modifiers = modifiers;

            BaseDuration = TimeSpan.FromSeconds(route.Duration.TotalSeconds / Transport.SpeedFactor);
            BaseCost = load.Slots.Sum(i => i.Key.Price * i.Value);
            BaseProfit = BaseGold = BaseMerchantRating = load.CalculateProfit(destination);
            BaseExperience = load.CalculateExperience(destination);

            Cost = BaseCost;
            Profit = (int)(BaseProfit * (1 + modifiers.Sum(m => m.ProfitBonus)));
            Gold = (int)(BaseGold * (1 + modifiers.Sum(m => m.GoldBonus)));
            MerchantRating = (int)(BaseMerchantRating * (1 + modifiers.Sum(m => m.MerchantRatingBonus)));
            Experience = (int)(BaseExperience * (1 + modifiers.Sum(m => m.ExpBonus)));
            Duration =
                TimeSpan.FromSeconds(route.Duration.TotalSeconds / (Transport.SpeedFactor + modifiers.Sum(m => m.SpeedBonus)));

            Gold = Math.Max(0, Gold);
            MerchantRating = Math.Max(0, MerchantRating);
            Experience = Math.Max(0, Experience);

            AddedCost = Cost - BaseCost;
            AddedProfit = Profit - BaseProfit;
            AddedGold = Gold - BaseGold;
            AddedMerchantRating = MerchantRating - BaseMerchantRating;
            AddedExperience = Experience - BaseExperience;
            AddedDuration = Duration - BaseDuration;

            ProfitPerSecond = Profit / Duration.TotalSeconds;

            if (source.NoProfits.Contains(destination.Id))
                Flags |= TradeFlags.NoProfit;

            if (route.Path.Select(w => w.Target.Region).Any(r => r.ChokePoint))
                Flags |= TradeFlags.ChokePoint;

            ModifierNames = string.Join(", ", Modifiers.Select(m => m.Name));
        }
Example #8
0
    private void InitializeMapLocations()
    {
        MapObjects = new List <GameObject>();
        List <PointLocation>   banks      = CurrentGame.Instance.gameDetail.banks;
        List <ServerTradePost> tradeposts = CurrentGame.Instance.gameDetail.tradePosts;

        //todo load all into map
        GameObject mapobj    = GameObject.Find("Map");
        GameObject container = new GameObject("TESTEST");        //todo get rid of this

        //GameObject container = GameObject.Find("MapElements");
        if (mapobj != null)
        {
            GOMap map = mapobj.GetComponent <GOMap>();
            if (map != null)
            {
                GameObject serverBanks = new GameObject("Server Banks");
                serverBanks.transform.parent = container.transform;
                foreach (PointLocation bank in banks)
                {
                    GameObject temp = (GameObject)Instantiate(Resources.Load("Bank"), Vector3.zero, Quaternion.identity);
                    temp.transform.parent = serverBanks.transform;
                    Bank bankScript = temp.GetComponent <Bank>();
                    if (bankScript != null)
                    {
                        bankScript.BankId = bank.id;
                    }


                    Coordinates coordinates = new Coordinates(bank.point.latitude, bank.point.longitude, 0);
                    GOObject    obj         = GOObject.AddComponentToObject(temp, map, coordinates);
                    Vector3     pos         = coordinates.convertCoordinateToVector(0);
                    pos.z = -3;
                    temp.transform.localPosition = pos;
                    MapObjects.Add(temp);
                }


                GameObject serverTPs = new GameObject("Server Tradingposts");
                serverTPs.transform.parent = container.transform;
                foreach (ServerTradePost tp in tradeposts)
                {
                    GameObject temp = (GameObject)Instantiate(Resources.Load("Tradingpost"), Vector3.zero, Quaternion.identity);
                    temp.transform.parent = serverTPs.transform;
                    TradingPost tpScript = temp.GetComponent <TradingPost>();
                    if (tpScript != null)
                    {
                        tpScript.TPId = tp.id;
                        //todo load flavorText?
                    }

                    GOObject obj = GOObject.AddComponentToObject(temp, map,
                                                                 new Coordinates(tp.point.latitude, tp.point.longitude, 1.0));
                    MapObjects.Add(temp);
                }

                GameObject playerHolder = new GameObject("Playerholder");                //todo is there a better way to do this?
                playerHolder.transform.parent = container.transform;
                List <ServerPlayer> players = CurrentGame.Instance.PlayerList();
                foreach (ServerPlayer serverPlayer in players)
                {
                    if (serverPlayer.ClientId.Equals(CurrentGame.Instance.LocalPlayer.ClientId))
                    {
                        continue;
                    }

                    GameObject temp = (GameObject)Instantiate(Resources.Load("Player"), Vector3.zero, Quaternion.identity);
                    temp.name             = serverPlayer.name;
                    temp.transform.parent = playerHolder.transform;
                    Person person = temp.GetComponent <Person>();
                    person.Player = serverPlayer;

                    GOObject obj = GOObject.AddComponentToObject(temp, map, new Coordinates(51.164510, 4.140199, 1.0));

                    CurrentGame.Instance.PlayerObjects.Add(serverPlayer.ClientId, temp);
                }
            }
            else
            {
                Debug.Log("ERROR: MAP NOT LOADED");
            }
        }
        else
        {
            Debug.Log("ERROR: MAP NOT LOADED");
        }
    }
Example #9
0
        public int CalculateExperience(TradingPost destination)
        {
            // http://wiki.mabinogiworld.com/view/Commerce
            // floor(sqrt(Single Item Profit * Single Item Weight)) * Item Quantity * 30

            return _slots.Sum(kvp =>
                (int)(Math.Sqrt(kvp.Key.Profits.First(x => x.Destination == destination).Amount * kvp.Key.Weight)) * kvp.Value * 30);
        }
Example #10
0
 public int CalculateProfit(TradingPost destination)
 {
     return _slots.Sum(kvp => kvp.Key.Profits.First(x => x.Destination == destination).Amount * kvp.Value);
 }
Example #11
0
 public int CalculateProfit(TradingPost destination)
 {
     return(_slots.Sum(kvp => kvp.Key.Profits.First(x => x.Destination == destination).Amount *kvp.Value));
 }