Exemplo n.º 1
0
    public void setMembers(UnitType t, Team team, int n)
    {
        UIManagerBehaviour.boxSelectManager.allUnits.Add(this);
        type      = t;
        this.team = team;
        var g = Units.getUnit(t);

        for (int i = 0; i < n; i++)
        {
            GameObject go            = GameObject.Instantiate(g);
            var        unitBehaviour = go.GetComponent <UnitBehaviour>();
            unitBehaviour.setPlatoon(this);
            units.Add(unitBehaviour);
            //go.transform.parent = this.transform;
        }

        buildModules(t);
        if (t == UnitType.AFV)
        {
            var ghost = GhostPlatoonBehaviour.build(UnitType.Infantry, team, n);
            transporter.setTransported(ghost.getRealPlatoon());
            ghost.setOrientation(100 * Vector3.down, 0);
            ghost.setVisible(false);
        }
        movement.setDestination(Vector3.forward);
    }
Exemplo n.º 2
0
        private void Update()
        {
            if (!_spawnQueue.Any())
            {
                return;
            }

            _spawnTime -= Time.deltaTime;
            if (_spawnTime > 0)
            {
                return;
            }


            GhostPlatoonBehaviour previewPlatoon = _spawnQueue.Dequeue();

            previewPlatoon.Spawn(transform.position);

            if (_spawnQueue.Count > 0)
            {
                _spawnTime += Constants.SPAWNPOINT_MIN_SPAWN_INTERVAL;
            }
            else
            {
                _spawnTime = Constants.SPAWNPOINT_QUEUE_DELAY;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create the smallest platoon allowed.
        /// </summary>
        private void StartNewPlatoon()
        {
            _smallestPlatoonSize = MIN_PLATOON_SIZE;
            _newestPlatoon       = GhostPlatoonBehaviour.CreatePreviewMode(Unit, Owner, MIN_PLATOON_SIZE);

            PreviewPlatoons.Add(_newestPlatoon);
        }
    public static GhostPlatoonBehaviour build(UnitType t, Team currentTeam, int count)
    {
        var behaviour = GhostPlatoonBehaviour.build();

        behaviour.setMembers(t, currentTeam, count);
        return(behaviour);
    }
Exemplo n.º 5
0
    public void Update()
    {
        if (!spawnQueue.Any())
        {
            return;
        }

        spawnTime -= Time.deltaTime;
        if (spawnTime > 0)
        {
            return;
        }


        GhostPlatoonBehaviour ghostPlatoon = spawnQueue.Dequeue();

        ghostPlatoon.Spawn(transform.position);

        if (spawnQueue.Count > 0)
        {
            spawnTime += MIN_SPAWN_INTERVAL;
        }
        else
        {
            spawnTime = QUEUE_DELAY;
        }
    }
Exemplo n.º 6
0
        public void CmdSplitPlatoon(uint platoonNetId)
        {
            NetworkIdentity identity;

            if (NetworkIdentity.spawned.TryGetValue(platoonNetId, out identity))
            {
                PlatoonBehaviour platoon = identity.gameObject.GetComponent <PlatoonBehaviour>();

                // We do not do something like 'while (Units.Count > 0)'
                // because the RPCs finish executing and hence update the unit count
                // way after the loop has concluded!
                int newPlatoonsCount = platoon.Units.Count - 1;
                while (newPlatoonsCount > 0)
                {
                    UnitDispatcher u         = platoon.Units[newPlatoonsCount];
                    uint           unitNetId = u.GetComponent <NetworkIdentity>().netId;
                    platoon.RpcRemoveUnit(unitNetId);

                    PlatoonBehaviour newPlatoon = PlatoonBehaviour.CreateGhostMode(
                        platoon.Unit, platoon.Owner);
                    GhostPlatoonBehaviour ghostPlatoon = newPlatoon.GhostPlatoon;

                    NetworkServer.Spawn(ghostPlatoon.gameObject);
                    NetworkServer.Spawn(newPlatoon.gameObject);

                    newPlatoon.RpcEstablishReferences(
                        ghostPlatoon.netId,
                        new[] { unitNetId });
                    newPlatoon.RpcActivate(u.Transform.position);

                    newPlatoonsCount--;
                }
            }
        }
        public void CmdSpawnPlatoon(
            byte playerId,
            byte categoryId,
            int unitId,
            int unitCount,
            Vector3 spawnPos,
            Vector3 destinationCenter,
            float destinationHeading)
        {
            Logger.LogNetworking(
                LogLevel.DEBUG,
                this,
                $"Spawning platoon at {spawnPos}");
            if (MatchSession.Current.Players.Count > playerId &&
                unitCount >= MIN_PLATOON_SIZE &&
                unitCount <= MAX_PLATOON_SIZE)
            {
                PlayerData owner = MatchSession.Current.Players[playerId];
                if (categoryId < owner.Deck.Categories.Length &&
                    unitId < MatchSession.Current.Armory.Categories[categoryId].Count)
                {
                    Unit unit = MatchSession.Current.Armory.Categories[categoryId][unitId];

                    PlatoonBehaviour      newPlatoon   = PlatoonBehaviour.CreateGhostMode(unit, owner);
                    GhostPlatoonBehaviour ghostPlatoon = newPlatoon.GhostPlatoon;

                    NetworkServer.Spawn(ghostPlatoon.gameObject);
                    NetworkServer.Spawn(newPlatoon.gameObject);

                    uint[] unitIds = new uint[unitCount];
                    for (int i = 0; i < unitCount; i++)
                    {
                        GameObject unitGO = Instantiate(unit.Prefab);
                        // Any added unit initialization must be done in an RPC,
                        // otherwise it won't show up on the clients!

                        NetworkServer.Spawn(unitGO);
                        unitIds[i] = unitGO.GetComponent <NetworkIdentity>().netId;
                    }

                    newPlatoon.RpcEstablishReferences(ghostPlatoon.netId, unitIds);
                    newPlatoon.RpcInitializeUnits();

                    ghostPlatoon.RpcSetOrientation(destinationCenter, destinationHeading);

                    newPlatoon.RpcActivate(spawnPos);
                }
                else
                {
                    Debug.LogError("Got bad unit id from a client.");
                }
            }
            else
            {
                // Got an invalid player id, server is trying to crash us?
                Debug.LogError(
                    "Client asked to create a platoon with an invalid player id.");
            }
        }
Exemplo n.º 8
0
        public BuyTransaction(UnitType type, PlayerData owner)
        {
            UnitType = type;
            Owner    = owner;

            _smallestPlatoonSize   = MIN_PLATOON_SIZE;
            _ghostPlatoonBehaviour =
                GhostPlatoonBehaviour.Build(type, owner, _smallestPlatoonSize);

            GhostPlatoons = new List <GhostPlatoonBehaviour>();
            GhostPlatoons.Add(_ghostPlatoonBehaviour);
        }
Exemplo n.º 9
0
        public void AddUnit()
        {
            if (_smallestPlatoonSize < MAX_PLATOON_SIZE)
            {
                GhostPlatoons.Remove(_ghostPlatoonBehaviour);
                _ghostPlatoonBehaviour.Destroy();

                _smallestPlatoonSize++;
                _ghostPlatoonBehaviour =
                    GhostPlatoonBehaviour.Build(UnitType, Owner, _smallestPlatoonSize);
                GhostPlatoons.Add(_ghostPlatoonBehaviour);
            }
            else
            {
                // If all platoons in the transaction are max size, we add a new one and update the size counter:
                _smallestPlatoonSize   = MIN_PLATOON_SIZE;
                _ghostPlatoonBehaviour = GhostPlatoonBehaviour.Build(UnitType, Owner, _smallestPlatoonSize);
                GhostPlatoons.Add(_ghostPlatoonBehaviour);
            }
        }
Exemplo n.º 10
0
    public void Initialize(UnitType t, PlayerData owner, int n)
    {
        Type  = t;
        Owner = owner;

        var iconInstance = Instantiate(Resources.Load <GameObject>("Icon"), transform);

        Icon           = iconInstance.GetComponent <IconBehaviour>();
        Icon.BaseColor = Owner.Team.Color;

        var unitPrefab = Owner.Session.Factory.FindPrefab(t);

        for (int i = 0; i < n; i++)
        {
            var unitInstance =
                Owner.Session.Factory.MakeUnit(unitPrefab, Owner.Team.Color);
            var unitBehaviour = unitInstance.GetComponent <UnitBehaviour>();
            unitBehaviour.SetPlatoon(this);
            Units.Add(unitBehaviour);

            var collider = unitInstance.GetComponentInChildren <BoxCollider>();
            collider.enabled = true;
        }

        BuildModules(t);

        if (t == UnitType.AFV)
        {
            var ghost = GhostPlatoonBehaviour.Build(UnitType.Infantry, owner, n);
            Transporter.SetTransported(ghost.GetRealPlatoon());
            ghost.SetOrientation(100 * Vector3.down, 0);
            ghost.SetVisible(false);
        }

        Movement.SetDestination(Vector3.forward);

        Icon.SetSource(Units);

        IsInitialized = true;
    }
Exemplo n.º 11
0
 public void setGhostPlatoon(GhostPlatoonBehaviour obj)
 {
     ghostPlatoon = obj;
 }
Exemplo n.º 12
0
        public void CmdSpawnPlatoon(
            byte playerId,
            byte unitCategoryId,
            int unitId,
            int unitCount,
            Vector3 spawnPos,
            Vector3 destinationCenter,
            float destinationHeading)
        {
            Logger.LogNetworking(
                LogLevel.DEBUG,
                this,
                $"Spawning platoon at {spawnPos}");
            if (MatchSession.Current.Players.Count > playerId &&
                unitCount >= MIN_PLATOON_SIZE &&
                unitCount <= MAX_PLATOON_SIZE)
            {
                PlayerData owner = MatchSession.Current.Players[playerId];
                if (unitCategoryId < owner.Deck.Categories.Length &&
                    unitId < GameSession.Singleton.Armory.Categories[unitCategoryId].Count)
                {
                    Unit unit = GameSession.Singleton.Armory.Categories[unitCategoryId][unitId];
                    Logger.LogNetworking(LogLevel.INFO,
                                         $"Spawning a platoon with category = {unitCategoryId}, unit id = {unitId}.");

                    PlatoonBehaviour      newPlatoon   = PlatoonBehaviour.CreateGhostMode(unit, owner);
                    GhostPlatoonBehaviour ghostPlatoon = newPlatoon.GhostPlatoon;
                    ghostPlatoon.transform.position = destinationCenter;
                    ghostPlatoon.FinalHeading       = destinationHeading;

                    NetworkServer.Spawn(ghostPlatoon.gameObject);
                    NetworkServer.Spawn(newPlatoon.gameObject);

                    uint[] unitIds = new uint[unitCount];
                    for (int i = 0; i < unitCount; i++)
                    {
                        GameObject unitGO = Instantiate(unit.Prefab);
                        // Any added unit initialization must be done in an RPC,
                        // otherwise it won't show up on the clients!

                        NetworkServer.Spawn(unitGO);
                        unitIds[i] = unitGO.GetComponent <NetworkIdentity>().netId;
                    }

                    newPlatoon.RpcEstablishReferences(ghostPlatoon.netId, unitIds);
                    newPlatoon.RpcInitializeUnits();

                    newPlatoon.RpcActivate(spawnPos);
                }
                else
                {
                    if (unitCategoryId < GameSession.Singleton.Armory.Categories.Length)
                    {
                        Logger.LogNetworking(LogLevel.ERROR,
                                             $"Got bad unit id = {unitId} from " +
                                             $"the server. Total units = {GameSession.Singleton.Armory.Categories[unitCategoryId].Count} " +
                                             $"(category = {unitCategoryId}).");
                    }
                    else
                    {
                        Logger.LogNetworking(LogLevel.ERROR,
                                             $"Got bad category id = {unitCategoryId} from " +
                                             $"the server. Total categories = {GameSession.Singleton.Armory.Categories.Length}");
                    }
                }
            }
            else
            {
                // Got an invalid player id, client is trying to crash us?
                Logger.LogNetworking(LogLevel.ERROR,
                                     $"Client asked to create a platoon with an invalid player id {playerId}.");
            }
        }
    public void buildUnit(UnitType t)
    {
        var behaviour = GhostPlatoonBehaviour.build(t, currentTeam, 4);

        addSpawn(behaviour);
    }
Exemplo n.º 14
0
        public void BuildUnit(UnitType t)
        {
            var behaviour = GhostPlatoonBehaviour.Build(t, _localPlayer, 4);

            _currentBuyTransaction.GhostPlatoons.Add(behaviour);
        }
Exemplo n.º 15
0
 public void BuyPlatoon(GhostPlatoonBehaviour previewPlatoon)
 {
     _spawnQueue.Enqueue(previewPlatoon);
 }
Exemplo n.º 16
0
 public void SetGhostPlatoon(GhostPlatoonBehaviour obj)
 {
     GhostPlatoon = obj;
 }
 private void addSpawn(GhostPlatoonBehaviour g)
 {
     spawningUnits    = true;
     enteringSpawning = true;
     spawnList.Add(g);
 }
Exemplo n.º 18
0
        public void CmdEnqueuePlatoonPurchase(
            byte playerId,
            byte unitCategoryId,
            int unitId,
            int unitCount,
            byte spawnPointId,
            Vector3 destinationCenter,
            float destinationHeading)
        {
            Logger.LogNetworking(
                LogLevel.DEBUG,
                this,
                $"Enqueueing platoon purchase at spawn pt = {spawnPointId}.");
            if (MatchSession.Current.Players.Count > playerId &&
                unitCount >= MIN_PLATOON_SIZE &&
                unitCount <= MAX_PLATOON_SIZE)
            {
                if (MatchSession.Current.SpawnPoints.Length > spawnPointId)
                {
                    PlayerData          owner = MatchSession.Current.Players[playerId];
                    SpawnPointBehaviour spawn = MatchSession.Current.SpawnPoints[spawnPointId];

                    if (unitCategoryId < owner.Deck.Categories.Length &&
                        unitId < GameSession.Singleton.Armory.Categories[unitCategoryId].Count)
                    {
                        Unit unit = GameSession.Singleton.Armory.Categories[unitCategoryId][unitId];

                        GhostPlatoonBehaviour g =
                            GhostPlatoonBehaviour.CreatePreviewMode(unit, owner, unitCount);
                        g.SetPositionAndOrientation(destinationCenter, destinationHeading);
                        NetworkServer.Spawn(g.gameObject);
                        spawn.BuyPlatoon(g);
                    }
                    else
                    {
                        if (unitCategoryId < GameSession.Singleton.Armory.Categories.Length)
                        {
                            Logger.LogNetworking(LogLevel.ERROR,
                                                 $"Got bad unit id = {unitId} from " +
                                                 $"the server. Total units = {GameSession.Singleton.Armory.Categories[unitCategoryId].Count} " +
                                                 $"(category = {unitCategoryId}).");
                        }
                        else
                        {
                            Logger.LogNetworking(LogLevel.ERROR,
                                                 $"Got bad category id = {unitCategoryId} from " +
                                                 $"the server. Total categories = {GameSession.Singleton.Armory.Categories.Length}");
                        }
                    }
                }
                else
                {
                    Logger.LogNetworking(LogLevel.ERROR,
                                         $"Client asked to create a platoon with an invalid spawn id {spawnPointId}.");
                }
            }
            else
            {
                // Got an invalid player id, client is trying to crash us?
                Logger.LogNetworking(LogLevel.ERROR,
                                     $"Client asked to create a platoon with an invalid player id {playerId}.");
            }
        }