public CustomShipInitializerModel(string model, ShipDriver driver) { var cs = new CompactSerializer(); this.model = cs.Deserialize <ShipSystemModel>(model); this.driver = driver; }
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); }
void SelectShip(MonoBehaviour behaviour) { var container = (ContainerItemView)behaviour; var shipName = container.GetModel <string>(); this.shipName.text = shipName; model = GameResources.GetShipSystemModel(shipName); ship.LoadShip(model); }
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; }
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"); }
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); }
public ShipIndexPair(int shipClass, int index) { this.model = null; this.shipClass = shipClass; this.index = index; }
public ShipIndexPair(ShipSystemModel model, int index) { this.model = model; this.shipClass = 0; this.index = index; }
public CustomShipInitializerModel(ShipSystemModel model, ShipDriver driver) { this.model = model; this.driver = driver; }
public override void OnOut() { ship.ClearShip(); model = null; shipName.text = ""; }
public void LoadShip(ShipSystemModel model) { CreateHull(model.hull.hullName); SetShip(model.hull, new ShipSystem(model).system); }