예제 #1
0
        public override void ResetSpawnTimer()
        {
            if (!GameMp.IsHost())
            {
                return;
            }

            base.ResetSpawnTimer();
            _fsm.SendEvent("Spawned");
        }
예제 #2
0
        public void Spawn(JObject json)
        {
            foreach (var spawn in json["spawns"])
            {
                var ship = (JObject)spawn;
                Debug.Log("spawn units scheduled at: " + json["scheduleId"]);

                ((GameMp)Game.Shared).ScheduleAt("spawn-unit", json["scheduleId"].ToObject <long>(),
                                                 json["packageId"].ToObject <int>(), () =>
                {
                    var shipUid    = ship["uid"].ToObject <int>();
                    var island     = Registry.Islands[ship["island_uid"].ToObject <int>()];
                    var islandData = island.GetComponent <IslandData>();

                    // 1) create ship by type
                    var go = GameObjectFactory.CreateShip(shipUid, islandData.ShipType,
                                                          islandData.PlayerData.playerType);

                    // 2) append ship at island
                    go.transform.Translate(island.transform.position);
                    go.transform.parent     = island.transform;
                    go.transform.localScale = new Vector3(1f, 1f, 1f);

                    // 3) set ship data
                    var shipData        = go.AddComponent <ShipData>();
                    shipData.shipType   = islandData.ShipType;
                    shipData.uid        = shipUid;
                    shipData.PlayerData = islandData.PlayerData;

                    // 4) colorize @see http://answers.unity3d.com/questions/483419/changing-color-of-children-of-instantiated-prefab.html
                    //go.GetComponentInChildren<Renderer>().material.color = island.renderer.material.color;

                    // 5) life data
                    var lifeData       = go.AddComponent <LifeData>();
                    lifeData.CurrentHp = lifeData.MaxHp = 10;

                    // 6) host fires attacks
                    if (GameMp.IsHost())
                    {
                        go.AddComponent <Assault>();
                        shipData.AttackDamage = 2;
                        shipData.AttackSpeed  = 1000;
                        go.AddComponent <Defence>();
                    }

                    // 7) re-enable spawning
                    island.GetComponentInChildren <SpawnUnitsMp>().ResetSpawnTimer();

                    // Debug.Log("spawn [uid=" + shipUid + "|type=" + shipData.shipType + "] at [uid=" + islandData.Uid + "|type=" + islandData.IslandType + "] for player [" + shipData.PlayerData.uid + "]");
                });
            }
        }