コード例 #1
0
    public CustomShipInitializerModel(string model, ShipDriver driver)
    {
        var cs = new CompactSerializer();

        this.model  = cs.Deserialize <ShipSystemModel>(model);
        this.driver = driver;
    }
コード例 #2
0
 public ShipController SetShip(ShipSystemModel model, ShipDriver driver)
 {
     this.ship = gameObject.AddComponent <ShipController>();
     this.ship.SetShip(shipClass, model, driver);
     SetHull(model.hull, this.ship.shipSystem.system, driver);
     this.ship.SetComponents(tackles.Select(t => t.GetComponent <ShipComponentBehaviour>()).Where(c => c != null).ToArray());
     return(this.ship);
 }
コード例 #3
0
    void SelectShip(MonoBehaviour behaviour)
    {
        var container = (ContainerItemView)behaviour;

        var shipName = container.GetModel <string>();

        this.shipName.text = shipName;

        model = GameResources.GetShipSystemModel(shipName);

        ship.LoadShip(model);
    }
コード例 #4
0
    public void SetShip(int shipClass, ShipSystemModel model, ShipDriver driver)
    {
        GetComponent <Rigidbody>().mass = Mathf.Pow(2, shipClass);
        shipDriver     = driver;
        shipSystem     = new ShipSystem(model);
        this.shipClass = shipClass;
        maxHealth      = new float[] { 1f, 4f, 12f, 36f, 250f * ((BattleConfig)GameState.sharedData["BattleConfig"]).battleDurationMultipier }[shipClass];// Mathf.Pow(maxHealth, shipClass + 1);
        health         = maxHealth;

        shipDriver.SetShip(this); //turn enabled true

        gameObject.AddComponent <ShipIdentification>().ship = this;
    }
コード例 #5
0
 static int GetShipClass(ShipSystemModel[][] models, ShipSystemModel model)
 {
     for (int i = 0; i < models.Length; i++)
     {
         foreach (var m in models[i])
         {
             if (m == model)
             {
                 return(i + 1);
             }
         }
     }
     throw new System.Exception("special model must be exist in array of other models");
 }
コード例 #6
0
        public static ShipSystemModel[] GenerateShipModels(ShipSystemModel[] models, int amount, float[] classWeights, IEnumerable <ShipIndexPair> specialShips = null)
        {
            var ships = models
                        .GroupBy(s => GameResources.GetShipHull(s.hull.hullName).shipClass)
                        .Where(s => s.Key > 0 && s.Key < 4)
                        .OrderBy(s => s.Key)
                        .Select(s => s.ToArray()).ToArray();

            int[] kShips = Algs.Split(amount, classWeights);

            var result = new LimitedRandomList <MyRandom <ShipSystemModel> >(ships
                                                                             .Select(kShips, (s, k) => new LimitedProperty <MyRandom <ShipSystemModel> >(new MyRandom <ShipSystemModel>(s), k)).ToArray()
                                                                             ).Select(v => (ShipSystemModel)v).ToArray();

            if (specialShips != null)
            {
                foreach (var s in specialShips)
                {
                    int             specialShipClass = s.GetShipClass(ships);
                    ShipSystemModel specialShipModel = s.GetModel(ships);

                    if (result[s.index] == specialShipModel)
                    {
                        continue;
                    }
                    else
                    {
                        //looking for same model in other position
                        for (int i = 0; i < amount; i++)
                        {
                            // next if index used by other special model
                            if (specialShips.Any(p => p.index == i))
                            {
                                continue;
                            }

                            if (result[i] == specialShipModel)
                            {
                                var t = result[i];
                                result[i]       = result[s.index];
                                result[s.index] = t;
                                goto NEXT;
                            }
                        }
                    }

                    if (GetShipClass(ships, result[s.index]) == specialShipClass)
                    {
                        result[s.index] = specialShipModel;
                        continue;
                    }
                    else
                    {
                        //looking for same model class in other position;
                        for (int i = 0; i < amount; i++)
                        {
                            // next if index used by other special model
                            if (specialShips.Any(p => p.index == i))
                            {
                                continue;
                            }

                            if (GetShipClass(ships, result[i]) == specialShipClass)
                            {
                                result[i]       = result[s.index];
                                result[s.index] = specialShipModel;
                                goto NEXT;
                            }
                        }
                    }
                    //Brute setting model
                    result[s.index] = specialShipModel;

NEXT:
                    continue;
                }
            }

            return(result);
        }
コード例 #7
0
 public ShipIndexPair(int shipClass, int index)
 {
     this.model     = null;
     this.shipClass = shipClass;
     this.index     = index;
 }
コード例 #8
0
 public ShipIndexPair(ShipSystemModel model, int index)
 {
     this.model     = model;
     this.shipClass = 0;
     this.index     = index;
 }
コード例 #9
0
 public CustomShipInitializerModel(ShipSystemModel model, ShipDriver driver)
 {
     this.model  = model;
     this.driver = driver;
 }
コード例 #10
0
 public override void OnOut()
 {
     ship.ClearShip();
     model         = null;
     shipName.text = "";
 }
コード例 #11
0
 public void LoadShip(ShipSystemModel model)
 {
     CreateHull(model.hull.hullName);
     SetShip(model.hull, new ShipSystem(model).system);
 }