CurrentProperty() public method

public CurrentProperty ( ) : NewChanges
return NewChanges
Esempio n. 1
0
        private void SelectObjectAtPoint()
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] hits = Physics.RaycastAll(ray);
            foreach (RaycastHit hit in hits)
            {
                GameObject obj = hit.collider.gameObject;
                //NOTE(Thompson): If all fails, change "tag" to "name", and "Unit" to "NewGameUnit".
                //This is now fixed, so we have two options here.
                if (obj.tag.Equals("Unit"))
                {
                    NewUnitStruct temp = new NewUnitStruct(obj);
                    NewGameUnit   unit = temp.unit.GetComponent <NewGameUnit>();
                    if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                    {
                        if (this.unitList.Contains(temp) && unit.hasAuthority)
                        {
                            if (!this.selectedList.Contains(temp))
                            {
                                this.changes       = unit.CurrentProperty();
                                changes.isSelected = true;
                                unit.NewProperty(changes);
                                CmdUpdateUnitProperty(unit.gameObject, this.changes);
                                this.selectedList.Add(temp);
                            }
                            else if (this.selectedList.Contains(temp))
                            {
                                this.changes            = unit.CurrentProperty();
                                this.changes.isSelected = false;
                                unit.NewProperty(changes);
                                CmdUpdateUnitProperty(unit.gameObject, this.changes);
                                this.selectedList.Remove(temp);
                            }
                        }
                    }
                    else
                    {
                        if (unit != null && unit.hasAuthority)
                        {
                            this.changes       = unit.CurrentProperty();
                            changes.isSelected = true;
                            unit.NewProperty(changes);
                            CmdUpdateUnitProperty(unit.gameObject, this.changes);
                            this.selectedList.Add(temp);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void CmdAttack(bool hasAuthority, GameObject attacker, GameObject victim, int damage)
        {
            if (victim != null && attacker != null)
            {
                NewGameUnit victimUnit   = victim.GetComponent <NewGameUnit>();
                NewGameUnit attackerUnit = attacker.GetComponent <NewGameUnit>();
                if (!(NetworkServer.FindLocalObject(victimUnit.netId) || NetworkServer.FindLocalObject(attackerUnit.netId)))
                {
                    return;
                }
                if (victimUnit != null && attackerUnit != null && !attackerUnit.properties.isAttackCooldownEnabled && NetworkServer.FindLocalObject(victimUnit.netId) != null && NetworkServer.FindLocalObject(attackerUnit.netId) != null)
                {
                    NewChanges changes = victimUnit.CurrentProperty();
                    changes.damage            = damage;
                    changes.isRecoveryEnabled = true;
                    victimUnit.NewProperty(changes);
                    RpcTakeDamageColor(victimUnit.netId);

                    if (victimUnit.properties.currentHealth == 0 && attackerUnit.hasAuthority == hasAuthority)
                    {
                        //TODO(Thompson): See if removing the authority check helps fixing the kill counter being
                        //only the server side can take kill counts, while client side sometimes not taking kill counts.
                        attackerUnit.LogKill();
                    }
                }
            }
        }
Esempio n. 3
0
 public void CmdDestroy(GameObject targetUnit)
 {
     if (targetUnit != null)
     {
         NewGameUnit unit = targetUnit.GetComponent <NewGameUnit>();
         if (unit != null && NetworkServer.FindLocalObject(unit.netId))
         {
             if (targetUnit != null)
             {
                 NewChanges changes = unit.CurrentProperty();
                 if (changes.targetUnit != null && changes.targetUnit.Equals(this.gameObject))
                 {
                     changes.targetUnit = null;
                     unit.NewProperty(changes);
                 }
             }
             NewLOS los = this.GetComponentInChildren <NewLOS>();
             if (los != null)
             {
                 los.parent = null;
             }
             NewAtkRange range = this.GetComponentInChildren <NewAtkRange>();
             if (range != null)
             {
                 range.parent = null;
             }
             NetworkServer.Destroy(this.gameObject);
         }
     }
 }
Esempio n. 4
0
 private void TempRectSelectObjects()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         if (temp.unit == null)
         {
             CmdRemoveUnitList(this.unitList[i].unit);
             continue;
         }
         Vector3 projectedPosition = Camera.main.WorldToScreenPoint(temp.unit.transform.position);
         projectedPosition.y = Screen.height - projectedPosition.y;
         if (this.selectionBox.Contains(projectedPosition))
         {
             NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>();
             if (unit.properties.isSelected || !unit.hasAuthority)
             {
                 continue;
             }
             if (temp.unit == null)
             {
                 CmdRemoveUnitList(this.unitList[i].unit);
                 continue;
             }
             this.changes            = unit.CurrentProperty();
             this.changes.isSelected = true;
             CmdUpdateUnitProperty(unit.gameObject, this.changes);
         }
         else
         {
             continue;
         }
     }
 }
Esempio n. 5
0
        private void CastRay(NewGameUnit unit, bool isMinimap, Vector3 mousePosition, Camera minimapCamera)
        {
            Ray ray;

            if (isMinimap)
            {
                ray = this.minimapCamera.ViewportPointToRay(mousePosition);
            }
            else
            {
                ray = Camera.main.ScreenPointToRay(mousePosition);
            }
            RaycastHit[] hits = Physics.RaycastAll(ray, 500f);
            foreach (RaycastHit hit in hits)
            {
                if (hit.collider.gameObject.tag.Equals("Floor"))
                {
                    this.changes = unit.CurrentProperty();
                    this.changes.mousePosition = hit.point;
                    this.changes.isCommanded   = true;
                    CmdUpdateUnitProperty(unit.gameObject, this.changes);
                    break;
                }
            }
        }
Esempio n. 6
0
        public void CmdInitialize(GameObject spawner)
        {
            NetworkIdentity spawnerID = spawner.GetComponent <NetworkIdentity>();

            //Only the server choose what color values to use. Client values do not matter.
            int colorValue = NewSpawner.colorCode;

            NewSpawner.colorCode = (++NewSpawner.colorCode) % 3;
            Color color;

            switch (colorValue)
            {
            default:
                color = Color.gray;
                break;

            case 0:
                color = Color.yellow;
                break;

            case 1:
                color = Color.blue;
                break;

            case 2:
                color = Color.green;
                break;
            }


            GameObject gameUnit = MonoBehaviour.Instantiate <GameObject>(this.newGameUnitPrefab);

            gameUnit.name = gameUnit.name.Substring(0, gameUnit.name.Length - "(Clone)".Length);
            gameUnit.transform.SetParent(this.transform);
            gameUnit.transform.position = this.transform.position;
            NewGameUnit b       = gameUnit.GetComponent <NewGameUnit>();
            NewChanges  changes = b.CurrentProperty();

            if (!changes.isInitialized)
            {
                changes.isInitialized = false;
                changes.teamColor     = color;
                changes.teamFactionID = (int)(Random.value * 100f);                 //This is never to be changed.
            }
            b.NewProperty(changes);
            NetworkServer.SpawnWithClientAuthority(b.gameObject, spawnerID.clientAuthorityOwner);

            RpcAdd(gameUnit, spawner);
            RpcFilter(b.netId, spawnerID.netId);
        }
Esempio n. 7
0
 public void CmdRecover(GameObject recoveringObject, int healValue)
 {
     if (recoveringObject != null)
     {
         NewGameUnit unit = recoveringObject.GetComponent <NewGameUnit>();
         if (unit != null && NetworkServer.FindLocalObject(unit.netId))
         {
             if (unit.properties.currentHealth < unit.properties.maxHealth && unit.properties.isRecoveryEnabled)
             {
                 NewChanges changes = unit.CurrentProperty();
                 changes.heal = healValue;
                 unit.NewProperty(changes);
             }
         }
     }
 }
Esempio n. 8
0
        public void CmdSplitSpawn(GameObject owner, NetworkIdentity ownerIdentity)
        {
            NewGameUnit unit    = owner.GetComponent <NewGameUnit>();
            NewChanges  changes = unit.CurrentProperty();

            changes.isSelected  = false;
            changes.isSplitting = true;
            changes.teamColor   = unit.GetTeamColor();
            unit.NewProperty(changes);
            GameObject split = MonoBehaviour.Instantiate <GameObject>(owner);

            split.name = "NewGameUnit";
            split.transform.SetParent(this.transform);
            split.transform.position = unit.transform.position;
            unit = split.GetComponent <NewGameUnit>();
            unit.NewProperty(changes);
            NetworkServer.SpawnWithClientAuthority(split, ownerIdentity.clientAuthorityOwner);
            RpcAddSplit(owner, split, changes, Random.Range(-180f, 180f));
            //this.splitList.Add(new Split(temp.transform, unit.transform));
            RpcOrganizeUnit(owner, split);
        }
Esempio n. 9
0
 private void SelectObjects()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         GameObject    obj  = temp.unit.gameObject;
         if (obj == null)
         {
             this.unitList.Remove(temp);
             continue;
         }
         if (this.selectedList.Contains(temp))
         {
             NewGameUnit unit = obj.GetComponent <NewGameUnit>();
             if (unit != null && unit.hasAuthority)
             {
                 this.changes       = unit.CurrentProperty();
                 changes.isSelected = true;
                 CmdUpdateUnitProperty(unit.gameObject, this.changes);
             }
         }
     }
 }
Esempio n. 10
0
 private void ClearSelectObjects()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         if (temp.unit == null)
         {
             CmdRemoveUnitList(this.unitList[i].unit);
             continue;
         }
         GameObject obj = temp.unit.gameObject;
         if (obj == null)
         {
             CmdRemoveUnitList(this.unitList[i].unit);
             continue;
         }
         NewGameUnit unit = obj.GetComponent <NewGameUnit>();
         changes            = unit.CurrentProperty();
         changes.isSelected = false;
         CmdUpdateUnitProperty(unit.gameObject, this.changes);
     }
     this.selectedList.Clear();
 }
Esempio n. 11
0
 private void SelectObjectsInRect()
 {
     for (int i = this.unitList.Count - 1; i >= 0; i--)
     {
         NewUnitStruct temp = this.unitList[i];
         GameObject    obj  = temp.unit.gameObject;
         if (obj == null)
         {
             this.unitList.Remove(temp);
             continue;
         }
         NewGameUnit unit = obj.GetComponent <NewGameUnit>();
         Vector3     projectedPosition = Camera.main.WorldToScreenPoint(obj.transform.position);
         projectedPosition.y = Screen.height - projectedPosition.y;
         if (unit != null && unit.hasAuthority)
         {
             if (this.isBoxSelecting)
             {
                 if (this.selectionBox.Contains(projectedPosition))
                 {
                     if (this.selectedList.Contains(temp))
                     {
                         this.changes            = unit.CurrentProperty();
                         this.changes.isSelected = false;
                         CmdUpdateUnitProperty(unit.gameObject, this.changes);
                         this.selectedList.Remove(temp);
                     }
                     else
                     {
                         this.changes       = unit.CurrentProperty();
                         changes.isSelected = true;
                         CmdUpdateUnitProperty(unit.gameObject, this.changes);
                         this.selectedList.Add(temp);
                     }
                 }
             }
             else
             {
                 if (unit.properties.isSelected)
                 {
                     if (!this.selectedList.Contains(temp))
                     {
                         this.selectedList.Add(temp);
                     }
                 }
                 else
                 {
                     if (!this.selectionBox.Contains(projectedPosition))
                     {
                         if (this.selectedList.Contains(temp))
                         {
                             this.changes            = unit.CurrentProperty();
                             this.changes.isSelected = false;
                             CmdUpdateUnitProperty(unit.gameObject, this.changes);
                             this.selectedList.Remove(temp);
                         }
                     }
                     else
                     {
                         if (!this.selectedList.Contains(temp))
                         {
                             this.changes = unit.CurrentProperty();
                             ;
                             changes.isSelected = true;
                             CmdUpdateUnitProperty(unit.gameObject, this.changes);
                             this.selectedList.Add(temp);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 12
0
        private void ManageNonAuthorityLists()
        {
            if (this.splitList.Count > 0)
            {
                for (int i = this.splitList.Count - 1; i >= 0; i--)
                {
                    Split splitGroup = this.splitList[i];
                    if (splitGroup.owner == null || splitGroup.split == null)
                    {
                        this.splitList.Remove(splitGroup);
                    }
                    if (splitGroup.elapsedTime > 1f)
                    {
                        NewGameUnit unit    = splitGroup.owner.GetComponent <NewGameUnit>();
                        NewChanges  changes = unit.CurrentProperty();
                        changes.isSelected  = false;
                        changes.isSplitting = false;
                        //CmdUpdateUnitProperty(splitGroup.owner.gameObject, changes);
                        unit.NewProperty(changes);
                        unit = splitGroup.split.GetComponent <NewGameUnit>();
                        unit.NewProperty(changes);
                        //CmdUpdateUnitProperty(splitGroup.split.gameObject, changes);
                        //this.unitList.Add(new NewUnitStruct(splitGroup.split.gameObject));
                        this.splitList.Remove(splitGroup);

                        //GameMetricLogger.Increment(GameMetricOptions.Splits);
                    }
                    else
                    {
                        splitGroup.Update();
                        this.splitList[i] = splitGroup;
                    }
                }
            }
            if (this.mergeList.Count > 0)
            {
                for (int i = this.mergeList.Count - 1; i >= 0; i--)
                {
                    Merge mergeGroup = this.mergeList[i];
                    if (mergeGroup.elapsedTime > 1f)
                    {
                        if (mergeGroup.merge != null)
                        {
                            NewGameUnit unit = mergeGroup.merge.GetComponent <NewGameUnit>();
                            if (unit != null)
                            {
                                NewChanges changes = unit.CurrentProperty();
                                changes.damage = unit.properties.maxHealth;
                                unit.NewProperty(changes);
                            }
                            NewUnitStruct temp = new NewUnitStruct();
                            temp.unit = unit.gameObject;
                            this.unitList.Remove(temp);
                            //CmdDestroy(temp.unit);
                        }
                        this.mergeList.RemoveAt(i);

                        //GameMetricLogger.Increment(GameMetricOptions.Merges);
                    }
                    else
                    {
                        mergeGroup.Update();
                        this.mergeList[i] = mergeGroup;
                    }
                }
            }
        }
Esempio n. 13
0
        private void ManageLists()
        {
            if (this.splitList.Count > 0)
            {
                for (int i = this.splitList.Count - 1; i >= 0; i--)
                {
                    Split splitGroup = this.splitList[i];
                    if (splitGroup.owner == null || splitGroup.split == null)
                    {
                        this.splitList.Remove(splitGroup);
                    }
                    if (splitGroup.elapsedTime > 1f)
                    {
                        NewGameUnit unit = splitGroup.owner.GetComponent <NewGameUnit>();
                        this.changes             = unit.CurrentProperty();
                        this.changes.isSelected  = false;
                        this.changes.isSplitting = false;
                        CmdUpdateUnitProperty(splitGroup.owner.gameObject, this.changes);
                        unit = splitGroup.split.GetComponent <NewGameUnit>();
                        CmdUpdateUnitProperty(splitGroup.split.gameObject, this.changes);
                        this.unitList.Add(new NewUnitStruct(splitGroup.split.gameObject));
                        this.splitList.Remove(splitGroup);

                        GameMetricLogger.Increment(GameMetricOptions.Splits);
                    }
                    else
                    {
                        splitGroup.Update();
                        this.splitList[i] = splitGroup;
                    }
                }
            }
            if (this.mergeList.Count > 0)
            {
                for (int i = this.mergeList.Count - 1; i >= 0; i--)
                {
                    Merge mergeGroup = this.mergeList[i];
                    if (mergeGroup.elapsedTime > 1f)
                    {
                        if (mergeGroup.owner != null)
                        {
                            NewGameUnit unit = mergeGroup.owner.gameObject.GetComponent <NewGameUnit>();
                            this.changes            = unit.CurrentProperty();
                            this.changes.isMerging  = false;
                            this.changes.isSelected = false;
                            //changes.newLevel = unit.properties.level + 1;
                            CmdUpdateUnitProperty(mergeGroup.owner.gameObject, this.changes);
                        }
                        if (mergeGroup.merge != null)
                        {
                            NewUnitStruct temp = new NewUnitStruct();
                            temp.unit = mergeGroup.merge.gameObject;
                            this.unitList.Remove(temp);
                            CmdDestroy(temp.unit);
                        }
                        this.mergeList.RemoveAt(i);

                        GameMetricLogger.Increment(GameMetricOptions.Merges);
                    }
                    else
                    {
                        mergeGroup.Update();
                        this.mergeList[i] = mergeGroup;
                    }
                }
            }
            this.isUnitListEmpty = this.unitList.Count <= 0;
            if (!this.isUnitListEmpty)
            {
                for (int i = this.unitList.Count - 1; i >= 0; i--)
                {
                    if (this.unitList[i].unit == null)
                    {
                        this.unitList.RemoveAt(i);
                        continue;
                    }
                    NetworkIdentity id = this.unitList[i].unit.GetComponent <NetworkIdentity>();
                    if (!id.hasAuthority)
                    {
                        CmdRemoveUnitList(this.unitList[i].unit);
                    }
                }
            }
            else
            {
                CmdShowReport();
            }
        }
Esempio n. 14
0
        //-----------   Private class methods may all need refactoring   --------------------

        private void HandleInputs()
        {
            if (Input.GetKeyUp(KeyCode.S))
            {
                foreach (NewUnitStruct temp in this.selectedList)
                {
                    NewGameUnit newUnit = temp.unit.GetComponent <NewGameUnit>();
                    if (!newUnit.properties.isSplitting && this.unitList.Count < NewSpawner.MAX_UNIT_LIMIT && newUnit.properties.level == 1)
                    {
                        CmdSplitSpawn(temp.unit, temp.unit.GetComponent <NetworkIdentity>());
                    }
                    else
                    {
                        if (newUnit != null)
                        {
                            this.changes             = newUnit.CurrentProperty();
                            this.changes.isSelected  = false;
                            this.changes.isSplitting = false;
                            newUnit.NewProperty(this.changes);
                        }
                    }
                }
                this.selectedList.Clear();
            }
            else if (Input.GetKeyUp(KeyCode.D))
            {
                NewGameUnit owner = null, merge = null;
                if (this.selectedList.Count == 1)
                {
                    owner                   = this.selectedList[0].unit.GetComponent <NewGameUnit>();
                    this.changes            = owner.CurrentProperty();
                    this.changes.isSelected = false;
                    owner.NewProperty(this.changes);
                }
                else
                {
                    for (int i = this.selectedList.Count - 1; i >= 1; i--)
                    {
                        owner = this.selectedList[i].unit.GetComponent <NewGameUnit>();
                        if (owner != null && !owner.properties.isMerging)
                        {
                            for (int j = i - 1; j >= 0; j--)
                            {
                                merge = this.selectedList[j].unit.GetComponent <NewGameUnit>();
                                this.doNotAllowMerging = false;
                                if (owner.properties.level == 1 && merge.properties.level == 1)
                                {
                                    CheckAvailableResource();
                                }
                                if (merge != null && !merge.properties.isMerging && merge.properties.level == owner.properties.level && !this.doNotAllowMerging)
                                {
                                    this.changes       = owner.CurrentProperty();
                                    changes.isMerging  = true;
                                    changes.isSelected = false;

                                    changes.newLevel++;
                                    changes.newMaxHealth      = this.unitAttributesManager.healthPrefabList[changes.newLevel];
                                    changes.newAttack         = this.unitAttributesManager.attackPrefabList[changes.newLevel];
                                    changes.newSpeed          = this.unitAttributesManager.speedPrefabList[changes.newLevel];
                                    changes.newSplit          = this.unitAttributesManager.splitPrefabFactor;
                                    changes.newMerge          = this.unitAttributesManager.mergePrefabList[changes.newLevel];
                                    changes.newAttackCooldown = this.unitAttributesManager.attackCooldownPrefabList[changes.newLevel];

                                    CmdUpdateUnitProperty(owner.gameObject, this.changes);
                                    CmdUpdateUnitProperty(merge.gameObject, this.changes);
                                    CmdMergeUpdate(owner.gameObject, merge.gameObject, this.changes);
                                    this.selectedList.RemoveAt(i);
                                    i--;
                                    this.selectedList.RemoveAt(j);
                                    j--;
                                    break;
                                }
                                else
                                {
                                    if (merge != null)
                                    {
                                        this.changes            = merge.CurrentProperty();
                                        this.changes.isSelected = false;
                                        this.changes.isMerging  = false;
                                        merge.NewProperty(this.changes);
                                        //this.selectedList.RemoveAt(j);
                                        //i--;
                                        //j--;
                                    }
                                }
                            }
                            if (merge == null)
                            {
                                this.changes            = owner.CurrentProperty();
                                this.changes.isSelected = false;
                                this.changes.isMerging  = false;
                                owner.NewProperty(this.changes);
                                //this.selectedList.RemoveAt(i);
                                //i--;
                            }
                        }
                        else if (owner != null)
                        {
                            this.changes            = owner.CurrentProperty();
                            this.changes.isSelected = false;
                            this.changes.isMerging  = false;
                            owner.NewProperty(this.changes);
                            //this.selectedList.RemoveAt(i);
                            //i--;
                        }
                    }
                }
            }
            if (Input.GetMouseButtonUp(1) && !this.minimapCamera.rect.Contains(this.screenPoint))
            {
                Ray          ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit[] hits = Physics.RaycastAll(ray);
                foreach (RaycastHit hit in hits)
                {
                    if (hit.collider.gameObject.tag.Equals("Floor"))
                    {
                        foreach (NewUnitStruct temp in this.selectedList)
                        {
                            if (temp.unit == null)
                            {
                                continue;
                            }
                            NewGameUnit unit = temp.unit.GetComponent <NewGameUnit>();
                            this.changes = unit.CurrentProperty();
                            this.changes.mousePosition = hit.point;
                            this.changes.isCommanded   = true;
                            CmdUpdateUnitProperty(temp.unit, this.changes);
                        }
                    }
                }
            }
        }