Ejemplo n.º 1
0
 public Dependency(CarStatistic otherStatistic, CarStatisticParam param, SIGN sign, CarStatistic thisStatistic)
 {
     Param          = param;
     Sign           = sign;
     OtherStatistic = otherStatistic;
     ThisStatistic  = thisStatistic;
 }
    internal void Deserialize(string serialized)
    {
        Dictionary <string, object> dict = (Dictionary <string, object>)MiniJSON.Json.Deserialize(serialized);

        foreach (KeyValuePair <string, object> kvp in dict)
        {
            CarStatistic cs = CarStatistic.Deserialize((string)kvp.Value);
            if (cs != null)
            {
                CarStatistics[cs.Type] = cs;
            }
        }

        //dependencies. those car statistics must to be in every carConfig.
        CarStatistic startingOil = CarStatistics[CarStatisticType.STARTING_OIL];
        CarStatistic fuelTank    = CarStatistics[CarStatisticType.FUEL_TANK];

        startingOil.AddDependency(new Dependency(fuelTank, CarStatisticParam.Value, SIGN.BIGGER, startingOil));

        //unlockables.
        CarStatistic shield = CarStatistics [CarStatisticType.SHIELD];

        shield.AddUnlockable(delegate(PlayerState ps, CarStatistic cs){
            return(ps.EverEarnedCoins > 1000);
        });
    }
    public static CarStatistic Deserialize(string serialized)
    {
        Dictionary <string, object> dict = (Dictionary <string, object>)MiniJSON.Json.Deserialize(serialized);
        CarStatistic cs = null;

        if (dict.ContainsKey("Type"))
        {
            CarStatisticType type = (CarStatisticType)System.Enum.Parse(typeof(CarStatisticType), (string)dict["Type"]);
            cs       = new CarStatistic(type);
            cs.Level = int.Parse((string)dict["Level"]);
        }
        return(cs);
    }
Ejemplo n.º 4
0
    public void Prepare(CarStatistic shield)
    {
        shieldValue    = (int)shield.Value;
        ShieldRenderer = new GameObject();
        SpriteRenderer r       = ShieldRenderer.AddComponent <SpriteRenderer>();
        Texture2D      shieldT = (Texture2D)SpriteManager.GetShield();

        r.sprite           = Sprite.Create(shieldT, new Rect(0, 0, shieldT.width, shieldT.height), new Vector2(0.5f, 0.5f));
        r.sortingLayerName = "Layer4";
        ShieldRenderer.transform.parent     = gameObject.transform;
        ShieldRenderer.name                 = "Shield";
        ShieldRenderer.transform.localScale = new Vector3(1, 1, 0);
    }
    override protected void OnGUIInner()
    {
        PlayerState state = Game.Me.Player;

        GuiHelper.DrawAtTop("Adventure mode");
        GuiHelper.DrawBeneathLine("Available coins: " + state.Coins);         //, GuiHelper.SmallFontTop, 0.1, 0.2, 0.8, 0.1);

        float y = 0.38f;

        foreach (KeyValuePair <CarStatisticType, CarStatistic> kvp in state.CarConfig.CarStatistics)
        {
            CarStatistic cs = kvp.Value;
            if (cs.IsUnlockedFor(state))
            {
                AfterButton upgrade = delegate() {
                    ScreenUpgrade su = gameObject.AddComponent <ScreenUpgrade>();
                    su.PrepareWith(cs);
                    Destroy(this);
                };

                string inBrackets = "";
                if (!cs.Type.AboveMinimum(cs.Type.ValueForLevel(cs.Level + 1)))
                {
                    inBrackets = "(Best)";
                }
                else if (cs.CanUpgrade(state.Coins))
                {
                    inBrackets = "(Upg for " + cs.UpgradeCost() + ")";
                }
                string text = cs.Type.Name() + ": " + cs.ValueFormatted + " " + inBrackets;
                GuiHelper.ButtonWithText(0.5, y, 1, 0.15, text, SpriteManager.GetRectangleButton(), GuiHelper.MicroFont, upgrade);


                //this has to be drawn after button with text because of overlay
                if (cs.CanUpgrade(state.Coins))
                {
                    GuiHelper.ButtonWithText(0.9, y, 0.15, 0.15, "", SpriteManager.GetUpArrow(), GuiHelper.MicroFont, upgrade);
                }
                y += 0.093f;
            }
        }


        GuiHelper.YesButton(delegate() {
            ScreenStartingMission ssm = gameObject.AddComponent <ScreenStartingMission>();
            Destroy(this);
        }, "Race");
    }
Ejemplo n.º 6
0
        public async Task <IEnumerable <CarStatistic> > GetCarStatisticsInPreviousDays(int days)
        {
            var travelPlans = _travelPlanService.GetTravelPlansInDateRange(days);

            var travelPlansGroupedByCar = travelPlans.ToList()
                                          .GroupBy(tp => new { tp.CarId, tp.Car }, (g, tp) => new
            {
                g.Car.CarId,
                g.Car,
                Trips = tp.Select(x => new
                {
                    x.TravelPlanId,
                    StartLocation = x.StartLocation.Name,
                    EndLcoation   = x.EndLocation.Name,
                    StartDate     = x.StartTimeUtc,
                    EndDate       = x.EndTimeUtc,
                    Employees     = x.TravelPlanEmployees.Select(tpe => tpe.Employee)
                })
            }).ToList();

            var carStatistics = new List <CarStatistic>();

            foreach (var car in travelPlansGroupedByCar)
            {
                var carStatistic = new CarStatistic()
                {
                    Car = car.Car.Adapt <CarDto>(),
                };

                var travelPlanStatistics = car.Trips.Select(t => new TravelPlanStatistic()
                {
                    TravelPlanId  = t.TravelPlanId,
                    Employees     = MapEmployee(t.Employees),
                    StartLocation = t.StartLocation,
                    EndLocation   = t.EndLcoation,
                    StartTimeUtc  = t.StartDate,
                    EndTimeUtc    = t.EndDate
                });
                carStatistic.TravelPlanStatistics.AddRange(travelPlanStatistics);

                carStatistics.Add(carStatistic);
            }

            return(carStatistics);
        }
    public CarConfig(string mode)
    {
        CarStatistic combustion  = new CarStatistic(CarStatisticType.COMBUSTION);
        CarStatistic fuelTank    = new CarStatistic(CarStatisticType.FUEL_TANK);
        CarStatistic wheel       = new CarStatistic(CarStatisticType.WHEEL);
        CarStatistic startingOil = new CarStatistic(CarStatisticType.STARTING_OIL);
        CarStatistic shield      = new CarStatistic(CarStatisticType.SHIELD);

        shield.AddUnlockable(delegate(PlayerState ps, CarStatistic cs){
            return(ps.EverEarnedCoins > 1000);
        });

        startingOil.AddDependency(new Dependency(fuelTank, CarStatisticParam.Value, SIGN.BIGGER, startingOil));

        CarStatistics.Add(CarStatisticType.COMBUSTION, combustion);
        CarStatistics.Add(CarStatisticType.FUEL_TANK, fuelTank);
        CarStatistics.Add(CarStatisticType.WHEEL, wheel);
        CarStatistics.Add(CarStatisticType.STARTING_OIL, startingOil);
        CarStatistics.Add(CarStatisticType.SHIELD, shield);

        switch (mode)
        {
        case MODE_CLASSIC: {
            startingOil.Value = 85;
            fuelTank.Value    = 100;
            wheel.Value       = 2f;
            _CarTexture       = SpriteManager.GetCar();
            combustion.Value  = 0.85f;
            break;
        }

        case MODE_ADV: {
            _CarTexture = SpriteManager.GetCarAdventure();
            break;
        }

        default:
            throw new UnityException("There is no mode " + mode + " in car config");
        }
    }
Ejemplo n.º 8
0
 public void PrepareWith(CarStatistic carStatistic)
 {
     CarStatistic = carStatistic;
 }
Ejemplo n.º 9
0
 public void Prepare(CarStatistic combustion, float startingCarSpeed)
 {
     v        = startingCarSpeed;
     RideCost = combustion.Value;
 }
Ejemplo n.º 10
0
 public void Prepare(CarStatistic wheel)
 {
     TurnSpeed = wheel.Value;
 }
Ejemplo n.º 11
0
 public void Prepare(CarStatistic fuelTank, CarStatistic startingOil)
 {
     MaxAmount = (int)fuelTank.Value;
     Amount    = (int)startingOil.Value;
 }
Ejemplo n.º 12
0
 public void BuyAndUpgrade(CarStatistic cs)
 {
     _Coins -= cs.UpgradeCost();
     cs.Upgrade();
 }