Esempio n. 1
0
        private static void loadConstants(GameCommander commander)
        {
            JObject tok = commander.exec <JObject>("PropertiesInterface", "getData");
            //Debug.Print(tok["properties"]["const_trains"].ToString());
            JObject const_trains = tok["properties"]["const_trains"] as JObject;

            if (const_trains != null)
            {
                JEnumerable <JProperty> children = const_trains.Children <JProperty>();
                foreach (JProperty child in children)
                {
                    TrainStats.addStats(child);
                }
            }

            //Debug.Print(tok["properties"]["const_train_upgrades"].ToString());
            JObject const_train_upgrades = tok["properties"]["const_train_upgrades"] as JObject;

            if (const_train_upgrades != null)
            {
                JEnumerable <JProperty> children = const_train_upgrades.Children <JProperty>();
                foreach (JProperty child in children)
                {
                    TrainUpgrade.addUpgrade(child);
                }
            }

            seedForTowns_ = tok["client"]["seedForTowns"].ToObject <int>();
        }
Esempio n. 2
0
        public static TrainStats getStats(EngineType type, HashSet <int> upgrades)
        {
            TrainStats stats = getStats(type);

            if (stats != null)
            {
                return(getStats(type).ApplyUpgrades(upgrades));
            }
            return(null);
        }
Esempio n. 3
0
 private TrainStats(TrainStats rhs)
 {
     type_         = rhs.type_;
     speed_        = rhs.speed_;
     acceleration_ = rhs.acceleration_;
     endurance_    = rhs.endurance_;
     maxWaggons_   = rhs.maxWaggons_;
     slotCount_    = rhs.slotCount_;
     price_        = rhs.price_;
     art_          = rhs.art_;
 }
Esempio n. 4
0
        internal static void addStats(JProperty prop)
        {
            EngineType et  = (EngineType)int.Parse(prop.Name);
            JObject    tok = prop.Value as JObject;

            if (tok != null)
            {
                TrainStats stats = new TrainStats(et, tok);
                stats_.Add(et, stats);
            }
        }
Esempio n. 5
0
        public TrainStats ApplyUpgrades(HashSet <int> upgrades)
        {
            TrainStats stats = new TrainStats(this);

            foreach (int uid in upgrades)
            {
                TrainUpgrade up = TrainUpgrade.getUpgrade(uid);
                if (up != null)
                {
                    switch (up.Type)
                    {
                    case UpgradeType.Acceleration:
                    {
                        stats.acceleration_ += up.Effect;
                        break;
                    }

                    case UpgradeType.Power:
                    {
                        stats.maxWaggons_ += up.Effect;
                        break;
                    }

                    case UpgradeType.Speed:
                    {
                        stats.speed_ += up.Effect;
                        break;
                    }

                    case UpgradeType.Reliability:
                    {
                        stats.endurance_ += up.Effect;
                        break;
                    }
                    }
                }
            }
            return(stats);
        }
Esempio n. 6
0
        public void refresh(JToken tok)
        {
            if (tok["reliability"] != null)
            {
                Reliability = float.Parse(tok["reliability"].ToString());
            }

            if (tok["profit_last_hour"] != null)
            {
                ProfitLastHour = int.Parse(tok["profit_last_hour"].ToString());
            }

            if (tok["profit_today"] != null)
            {
                ProfitToday = int.Parse(tok["profit_today"].ToString());
            }

            if (tok["mechanic_end"] != null)
            {
                double end = double.Parse(tok["mechanic_end"].ToString());
                MechanicEnd = DateTime.Now.AddSeconds(end);
            }
            if (tok["boost_end"] != null)
            {
                double boostEnd = double.Parse(tok["boost_end"].ToString());
                BoostEnd = DateTime.Now.AddSeconds(boostEnd);
            }

            if (tok["waggons"] != null)
            {
                load_.refresh(tok["waggons"]);
                if (baseNumWaggons_ > maxWaggons_)
                {
                    maxWaggons_ = baseNumWaggons_;
                }
                if (load_.MaxLoad > maxWaggons_)
                {
                    maxWaggons_ = load_.MaxLoad;
                }
                OnPropertyChanged("Load");
            }

            if (tok["upgrades"] != null && tok["upgrades"] is JArray)
            {
                JArray upgrades = tok["upgrades"] as JArray;
                if (upgrades.Count > 0)
                {
                    int new_ups = 0;
                    foreach (JToken u in upgrades)
                    {
                        int uid = u["id"].ToObject <int>();
                        if (!appliedUpgrades_.Contains(uid))
                        {
                            appliedUpgrades_.Add(uid);
                            ++new_ups;
                        }
                    }
                    if (new_ups > 0)
                    {
                        stats_ = null;
                        OnPropertyChanged("Stats");
                    }
                }
            }

            if (tok["navigation"] != null)
            {
                CurrentLocationId     = tok["navigation"]["current_location_id"].ToString();
                NextLocationId        = tok["navigation"]["next_location_id"].ToString();
                NextVisibleLocationId = tok["navigation"]["next_visible_location_id"].ToString();
            }
        }