示例#1
0
        private void RespondToAttack(Entity defenderEntity, Entity attackerEntity)
        {
            Targeter defenderTargeter = World.EntityManager.GetComponentData <Targeter>(defenderEntity);

            if (defenderTargeter.hasTarget == 0)
            {
                ZoxID       attackerID       = World.EntityManager.GetComponentData <ZoxID>(attackerEntity);
                Translation attackerPosition = World.EntityManager.GetComponentData <Translation>(attackerEntity);
                Translation defenderPosition = World.EntityManager.GetComponentData <Translation>(defenderEntity);
                // Now set to attack the attacker
                defenderTargeter.hasTarget       = 1;
                defenderTargeter.nearbyCharacter = new NearbyCharacter
                {
                    character = attackerEntity, // attackerID.id;
                    clan      = attackerID.clanID,
                    position  = attackerPosition.Value,
                    distance  = math.distance(defenderPosition.Value, attackerPosition.Value)
                };
                //defenderTargeter.targetClanID = attackerID.clanID;
                ////targeter.targetID = attackerEntityID;
                //defenderTargeter.targetPosition = attackerPosition.Value;
                //defenderTargeter.targetDistance =
                World.EntityManager.SetComponentData(defenderEntity, defenderTargeter);
                //Debug.LogError("Defender will now attack its target: " + attackerID.id);
            }
        }
示例#2
0
        private void SpawnPlayerBar(Entity character)//, float heightAddition)
        {
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character);

            if (frontBars.ContainsKey(zoxID.id))
            {
                Debug.LogError("Trying to add duplicate statbar onto character.");
                return;
            }
            Translation translation = World.EntityManager.GetComponentData <Translation>(character);
            Entity      backbar     = UIUtilities.SpawnPanel(World.EntityManager, character, uiData.backBarMaterial, null, panelSize);
            Entity      frontbar    = CreateBarUI(frontbarArchtype, translation.Value, uiData.frontBarMaterial, healthbarMesh);

            frontBars.Add(zoxID.id, frontbar);
            backBars.Add(zoxID.id, backbar);
            // backbar
            World.EntityManager.AddComponentData(backbar, zoxID);
            World.EntityManager.SetComponentData(frontbar, new Parent {
                Value = backbar
            });
            World.EntityManager.SetComponentData(frontbar, new StatBarUI {
                width = panelSize.x
            });
            World.EntityManager.SetComponentData(frontbar, zoxID);
            UIUtilities.UpdateOrbiter(World.EntityManager, backbar, orbitPosition, uiData.crosshairLerpSpeed);
        }
示例#3
0
        private void SpawnMonster(Entity e, SkillDatam datam)
        {
            if (World.EntityManager.HasComponent <CharacterRaycaster>(e) == false)
            {
                return;
            }
            int   monsterID               = datam.monster.Value.id;
            ZoxID zoxID                   = World.EntityManager.GetComponentData <ZoxID>(e);
            CharacterRaycaster caster     = World.EntityManager.GetComponentData <CharacterRaycaster>(e);
            WorldBound         worldBound = World.EntityManager.GetComponentData <WorldBound>(e);

            if (caster.DidCast() == 1)
            {
                ZoxID stats = World.EntityManager.GetComponentData <ZoxID>(e);
                //caster.triggered = 1;
                World.EntityManager.SetComponentData(e, caster);
                int clanID = stats.clanID;
                if (datam.Value.isSpawnHostile == 1)
                {
                    clanID = Bootstrap.GenerateUniqueID();
                }
                CharacterSpawnSystem.SpawnNPC(World.EntityManager, worldBound.world, monsterID, clanID, caster.voxelPosition, zoxID.id);

                /*if (datam.Value.isSpawnHostile != 1)
                 * {
                 *  Entity npc = characterSpawnSystem.characters[spawnedID];
                 *  ZoxID spawnedZoxID = World.EntityManager.GetComponentData<ZoxID>(npc);
                 *  spawnedZoxID.creatorID = zoxID.id;
                 *  World.EntityManager.SetComponentData(npc, spawnedZoxID);
                 * }*/
                AudioManager.instance.PlaySound(datam.audio, caster.voxelPosition);
                //Debug.LogError("Spawning Turret at: " + caster.voxelPosition.ToString());
            }
        }
示例#4
0
        public override bool Equals(object obj)
        {
            if (!(obj is ZoxID))
            {
                return(false);
            }
            ZoxID e = (ZoxID)obj;

            return(e.id == id);
        }
示例#5
0
        private void SpawnTurret(Entity e, int turretID)
        {
            CharacterRaycaster caster = World.EntityManager.GetComponentData <CharacterRaycaster>(e);

            if (caster.DidCast() == 1)
            {
                ZoxID stats = World.EntityManager.GetComponentData <ZoxID>(e);
                TurretSpawnerSystem.QueueTurret(caster.voxelPosition, turretID, stats.clanID);
                //caster.triggered = 1;
                //World.EntityManager.SetComponentData(e, caster);
                //Debug.LogError("Spawning Turret at: " + caster.voxelPosition.ToString());
            }
        }
示例#6
0
        protected override void OnUpdate()
        {
            Entities.WithAll <BulletHitTaker>().ForEach((Entity littlebitchEntity, ref BulletHitTaker littlebitch) =>
            {
                if (littlebitch.wasHit == 1)
                {
                    littlebitch.wasHit  = 0;
                    Entity bulletEntity = bulletSpawnSystem.bullets[littlebitch.bulletID];
                    if (World.EntityManager.HasComponent <Bullet>(bulletEntity))
                    {
                        Bullet bullet  = World.EntityManager.GetComponentData <Bullet>(bulletEntity);
                        ZoxID bulletID = World.EntityManager.GetComponentData <ZoxID>(bulletEntity);
                        if (characterSpawnSystem.characters.ContainsKey(bulletID.creatorID))
                        {
                            Entity attackingCharacter = characterSpawnSystem.characters[bulletID.creatorID];
                            DamageSystem.AddDamage(World.EntityManager,
                                                   attackingCharacter, littlebitchEntity, 1, bullet.damage);
                        }
                        else if (TurretSpawnerSystem.turrets.ContainsKey(bulletID.creatorID))
                        {
                            DamageSystem.AddDamage(World.EntityManager,
                                                   TurretSpawnerSystem.turrets[bulletID.creatorID], littlebitchEntity, 1, bullet.damage);
                        }
                        else
                        {
                            UnityEngine.Debug.LogError("Character does not exist: " + bulletID.id + " out of " + characterSpawnSystem.characters.Count + " characters.");
                        }
                        // get angle of hit
                        float3 littlebitchPosition = World.EntityManager.GetComponentData <Translation>(littlebitchEntity).Value;
                        float3 bulletPosition      = World.EntityManager.GetComponentData <Translation>(bulletEntity).Value;
                        float3 difference          = math.normalize(littlebitchPosition - bulletPosition);
#if UNITY_EDITOR
                        UnityEngine.Debug.DrawLine(bulletPosition, bulletPosition + difference, UnityEngine.Color.red, 5);
#endif
                        // add force to character
                        BodyForce force     = World.EntityManager.GetComponentData <BodyForce>(littlebitchEntity);
                        force.acceleration += difference * 1.5f;
                        World.EntityManager.SetComponentData(littlebitchEntity, force);

                        bulletDeathSystem.UseBullet(littlebitch.bulletID);
                    }
                    // else bullet has already been removed
                }
            });
        }
示例#7
0
        protected override void OnUpdate()
        {
            float time = UnityEngine.Time.time;

            Entities.WithAll <Translation, NearbyCharacters>().ForEach((Entity littlebitchEntity,
                                                                        ref Translation position, ref NearbyCharacters nearbyCharacters) =>
            {
                if (time - nearbyCharacters.lastUpdatedTime >= 1)
                {
                    nearbyCharacters.lastUpdatedTime = time;
                    //Debug.LogError(littlebitchEntity.Index + " is getting nearby characters " + time + " with characters: " + characterSpawnSystem.characters.Count);
                    // now update all nearby characters

                    List <Entity> nearbyCharacterEntities = new List <Entity>();
                    List <int> nearbyCharacterClans       = new List <int>();
                    List <float> nearbyCharacterDistances = new List <float>();
                    List <float3> nearbyPositions         = new List <float3>();
                    foreach (KeyValuePair <int, Entity> KVP in characterSpawnSystem.characters)
                    {
                        if (KVP.Value != littlebitchEntity)
                        {
                            // i should check their chunk position and compare it first - its quicker then calculating distances?
                            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(KVP.Value);
                            Translation otherPosition = World.EntityManager.GetComponentData <Translation>(KVP.Value);
                            float distanceTo          = math.distance(position.Value, otherPosition.Value);
                            if (distanceTo < 10)
                            {
                                nearbyCharacterEntities.Add(KVP.Value);
                                nearbyCharacterClans.Add(zoxID.clanID);
                                nearbyCharacterDistances.Add(distanceTo);
                                nearbyPositions.Add(otherPosition.Value);
                            }

                            /*else
                             * {
                             *  Debug.LogError("Creature is too far away");
                             * }*/
                        }
                    }
                    // now convert them all to nearbyCharacters arrays
                    nearbyCharacters.SetData(nearbyCharacterEntities, nearbyCharacterClans, nearbyCharacterDistances, nearbyPositions);
                }
            });
        }
示例#8
0
        protected void UpdateStatbar(Stats stats, Entity character, int stateIndex)
        {
            ZoxID zoxID       = World.EntityManager.GetComponentData <ZoxID>(character);
            int   characterID = zoxID.id;

            if (stateIndex != -1)
            {
                StateStaz targetStateStat = stats.states[stateIndex];
                if (targetStateStat.value == targetStateStat.maxValue)
                {
                    // new system needed - struct that contains multiple bars, for various state stats
                    if (StatbarSystem.frontBars.ContainsKey(characterID))
                    {
                        StatBarUI statBarUI = World.EntityManager.GetComponentData <StatBarUI>(StatbarSystem.frontBars[characterID]);
                        if (statBarUI.isTakingDamage == 1)
                        {
                            statBarUI.isTakingDamage = 0;
                            //statBarUI.timeStateChanged = UnityEngine.Time.time;
                            World.EntityManager.SetComponentData(StatbarSystem.frontBars[characterID], statBarUI);
                        }
                    }
                }
                //RegenStaz[] regens = stats.regens.ToArray();
                // later check for all regens, if the value increase to max
                //foreach (RegenStaz regen in regens)
                {
                    //RegenStaz regen = stats.regens[regenIndex];
                    // get index id

                    /*int targetStatIndex = -1;
                     * for (int i = 0; i < stats.states.Length; i++)
                     * {
                     *  if (stats.states[i].id == targetStatIndex)
                     *  {
                     *      targetStatIndex = i;
                     *      break;
                     *  }
                     * }
                     */
                }
            }
        }
示例#9
0
        /* public void LoadGame()
         * {
         *   Entity character = Bootstrap.instance.GetPlayerMonster();
         *   LoadPlayer(character);
         * }*/

        /// <summary>
        /// Players can chose any  character in the save game folder - then it will be loaded from that
        /// </summary>
        public void LoadPlayer(Entity character)
        {
            ZoxID zoxID = EntityManager.GetComponentData <ZoxID>(character);

            LoadComponentData <Translation>(character, "Players", zoxID.id.ToString());
            LoadComponentData <Rotation>(character, "Players", zoxID.id.ToString());
            LoadComponentData <Inventory>(character, "Players", zoxID.id.ToString());
            LoadComponentData <Stats>(character, "Players", zoxID.id.ToString());
            LoadComponentData <Skills>(character, "Players", zoxID.id.ToString());
            LoadComponentData <Equipment>(character, "Players", zoxID.id.ToString());
            LoadComponentData <QuestLog>(character, "Players", zoxID.id.ToString());
            if (World.EntityManager.HasComponent <CameraLink>(character))
            {
                CameraLink cameraLink = EntityManager.GetComponentData <CameraLink>(character);
                Entity     camera     = cameraLink.camera;// CameraSystem.cameras[cameraLink.cameraID];
                LoadComponentData <FirstPersonCamera>(camera, "Players", zoxID.id.ToString());
                FirstPersonCamera firstPersonCamera = EntityManager.GetComponentData <FirstPersonCamera>(camera);
                firstPersonCamera.enabled = 1;
                EntityManager.SetComponentData(camera, firstPersonCamera);
            }
        }
示例#10
0
        private void SavePlayer(Entity character)
        {
            ZoxID  zoxID        = EntityManager.GetComponentData <ZoxID>(character);
            string saveGamePath = GetSavePath() + saveGameName + "/";
            string playerPath   = saveGamePath + "Players/" + zoxID.id.ToString();

            if (!System.IO.Directory.Exists(playerPath))
            {
                System.IO.Directory.CreateDirectory(playerPath);
            }
            SaveComponentData <Translation>(character, "Players", zoxID.id.ToString());
            SaveComponentData <Rotation>(character, "Players", zoxID.id.ToString());
            SaveComponentData <Inventory>(character, "Players", zoxID.id.ToString());
            SaveComponentData <Stats>(character, "Players", zoxID.id.ToString());
            SaveComponentData <Skills>(character, "Players", zoxID.id.ToString());
            SaveComponentData <Equipment>(character, "Players", zoxID.id.ToString());
            SaveComponentData <QuestLog>(character, "Players", zoxID.id.ToString());
            if (World.EntityManager.HasComponent <CameraLink>(character))
            {
                CameraLink cameraLink = EntityManager.GetComponentData <CameraLink>(character);
                Entity     camera     = cameraLink.camera;// CameraSystem.cameras[cameraLink.cameraID];
                SaveComponentData <FirstPersonCamera>(camera, "Players", zoxID.id.ToString());
            }
        }
示例#11
0
        public void SpawnNPCBar(Entity character)
        {
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character);

            if (frontBars.ContainsKey(zoxID.id))
            {
                Debug.LogError("Trying to add duplicate statbar onto character.");
                return;
            }
            Translation translation    = World.EntityManager.GetComponentData <Translation>(character);
            Body        body           = World.EntityManager.GetComponentData <Body>(character);
            float       positionOffset = body.size.y * 1.2f + panelSize.y * 2f;
            float3      spawnPosition  = translation.Value + new float3(0, positionOffset, 0);
            Entity      backbar        = CreateBarUI(backbarArchtype, spawnPosition, uiData.backBarMaterial, healthbarMeshBackNPC);
            Entity      frontbar       = CreateBarUI(frontbarArchtype, spawnPosition, uiData.frontBarMaterial, healthbarMeshNPC);

            frontBars.Add(zoxID.id, frontbar);
            backBars.Add(zoxID.id, backbar);
            // backbar
            World.EntityManager.SetComponentData(backbar, zoxID);
            World.EntityManager.SetComponentData(backbar, new UITrailer {
                character      = character,
                heightAddition = positionOffset
            });
            // front bar
            World.EntityManager.SetComponentData(frontbar, zoxID);
            World.EntityManager.SetComponentData(frontbar, new Parent {
                Value = backbar
            });
            World.EntityManager.SetComponentData(frontbar, new StatBarUI {
                character        = character,
                percentage       = 1,
                targetPercentage = 1,
                width            = panelSizeNPC.x
            });
        }
示例#12
0
        private void DebugAIStates()
        {
            EntityManager manager = booty.GetSystems().space.EntityManager;
            //for (int i = 0; i < booty.systemsManager.characterSpawnSystem.characters.Count; i++)
            int count = 1;

            foreach (Entity character in booty.GetSystems().characterSystemGroup.characterSpawnSystem.characters.Values)
            {
                if (manager.HasComponent <AIState>(character))
                {
                    AIState state = manager.GetComponentData <AIState>(character);
                    ZoxID   zoxID = manager.GetComponentData <ZoxID>(character);
                    GUILayout.Label("[" + count + "] State: " + ((AIStateType)(state.state)) + ", Clan: " + zoxID.clanID + ", Creator: " + zoxID.creatorID + ", ID: " + zoxID.id);
                    Mover    mover    = manager.GetComponentData <Mover>(character);
                    Wander   wander   = manager.GetComponentData <Wander>(character);
                    Targeter targeter = manager.GetComponentData <Targeter>(character);
                    //GUILayout.Label("       [" + count + "] Mover: " + mover.disabled + ", Wander: " + wander.disabled + ", Target ID: " + targeter.target.Index);
                }
                else
                {
                    ZoxID zoxID = manager.GetComponentData <ZoxID>(character);
                    GUILayout.Label("[" + count + "] Clan: " + zoxID.clanID + ", Creator: " + zoxID.creatorID + ", ID: " + zoxID.id);
                    if (manager.HasComponent <Shooter>(character))
                    {
                        Shooter  shooter  = manager.GetComponentData <Shooter>(character);
                        Targeter targeter = manager.GetComponentData <Targeter>(character);
                        //GUILayout.Label("       Shooter: " + Quaternion.ToEulerAngles(shooter.shootRotation).ToString() + ", Target ID: " + targeter.targetID);
                    }
                }
                count++;
                if (count == 31)
                {
                    break;
                }
            }
        }
示例#13
0
        private void RewardVictor(ref Stats deadMonster, Entity attacker, ref Stats attackerStats, int defenderClanID, int defenderMetaID)
        {
            //int levelID = 0;

            /*if (!(StatsIndexes.experience < attackerStats.states.Length))
             * {
             *  Debug.LogError("States are too small, doesnt havexp in them: " + attackerStats.states.Length);
             *  return;
             * }*/
            if (attackerStats.levels.Length == 0)
            {
                return;
            }
            // should create a KillSystem that gives rewards
            //StateStaz experience = attackerStats.states[StatsIndexes.experience];
            Level attackerLevel = attackerStats.levels[0];
            // should pick up items called Soul Orbs that give you experience instead
            int levelValue = 0;

            if (deadMonster.levels.Length > 0)
            {
                levelValue = deadMonster.levels[0].value;
            }
            float experienceGiven = (levelValue + 1) * UnityEngine.Random.Range(0.5f, 1.5f);
            ZoxID attackerID      = World.EntityManager.GetComponentData <ZoxID>(attacker);

            if (attackerID.creatorID == 0)
            {
                // normal experience
                // Debug.LogError("Giving experience: " + experienceGiven);
                attackerLevel.experienceGained += experienceGiven;// adding health as experience, shouldnt be based on their level?
            }
            else
            {
                if (characterSpawnSystem.characters.ContainsKey(attackerID.creatorID) == false)
                {
                    //Debug.LogError("Creator does not exist.");
                    attackerLevel.experienceGained += experienceGiven;
                }
                else
                {
                    Entity summonerEntity = characterSpawnSystem.characters[attackerID.creatorID];
                    if (World.EntityManager.HasComponent <Stats>(summonerEntity))
                    {
                        Stats summoner = World.EntityManager.GetComponentData <Stats>(summonerEntity);
                        if (summoner.levels.Length > 0)
                        {
                            //StateStaz summonerExp = summoner.states[StatsIndexes.experience];
                            Level summonerLevel = summoner.levels[0];
                            summonerLevel.experienceGained += experienceGiven / 2f;
                            if (summonerLevel.experienceGained >= summonerLevel.experienceRequired)
                            {
                                summoner.leveledUp = 1;
                            }
                            summoner.levels[0] = summonerLevel;
                            World.EntityManager.SetComponentData(summonerEntity, summoner);
                            attackerLevel.experienceGained += experienceGiven / 2f;
                            StatsUISpawnSystem.OnUpdatedStat(World.EntityManager, summonerEntity, StatType.Level, 0);
                        }
                        else
                        {
                            attackerLevel.experienceGained += experienceGiven;
                        }
                    }
                    else
                    {
                        attackerLevel.experienceGained += experienceGiven;
                        //Debug.LogError("Creator exists. But has no stats.");
                        //experience.value += experienceGiven;// adding health as experience, shouldnt be based on their level?
                    }
                }
            }
            if (attackerLevel.experienceGained >= attackerLevel.experienceRequired)
            {
                attackerStats.leveledUp = 1;
            }
            attackerStats.levels[0] = attackerLevel;
            World.EntityManager.SetComponentData(attacker, attackerStats);
            StatsUISpawnSystem.OnUpdatedStat(World.EntityManager, attacker, StatType.Level, 0);

            // give quest completion stat to the character

            if (characterSpawnSystem.characters.ContainsKey(attackerID.id))
            {
                Entity characterEntity = characterSpawnSystem.characters[attackerID.id];
                // get questlog
                if (World.EntityManager.HasComponent <QuestLog>(characterEntity))
                {
                    QuestLog questLog = World.EntityManager.GetComponentData <QuestLog>(characterEntity);
                    if (questLog.OnKilledCharacter(defenderMetaID))
                    {
                        World.EntityManager.SetComponentData(characterEntity, questLog);
                        // update questlog UI
                        //Bootstrap.instance.systemsManager.questLogUISpawnSystem.UpdateUI(createdID.id);
                    }
                }
            }
        }
示例#14
0
        public void UpdateStatUI(UpdateStatUICommand command)
        {
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(command.character);

            if (!uis.ContainsKey(zoxID.id))
            {
                return; // character died
            }
            Stats     stats        = World.EntityManager.GetComponentData <Stats>(command.character);
            Entity    ui           = uis[zoxID.id];
            Childrens children     = World.EntityManager.GetComponentData <Childrens>(ui);
            int       uiArrayIndex = command.statIndex;

            if (command.statType == (byte)StatType.Base)
            {
                Staz      stat  = stats.stats[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.stats.Length;
            }
            if (command.statType == (byte)StatType.State)
            {
                StateStaz stat  = stats.states[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);

                /*Entity textEntity2 = texts.children[0];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.maxValue).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);*/
            }
            else
            {
                uiArrayIndex += stats.states.Length;
            }
            if (command.statType == (byte)StatType.Regen)
            {
                RegenStaz stat  = stats.regens[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.regens.Length;
            }
            if (command.statType == (byte)StatType.Attribute)
            {
                AttributeStaz stat  = stats.attributes[command.statIndex];
                Entity        icon  = children.children[uiArrayIndex];
                Childrens     texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.attributes.Length;
            }
            if (command.statType == (byte)StatType.Level)
            {
                Level      stat       = stats.levels[command.statIndex];
                Entity     icon       = children.children[uiArrayIndex];
                Childrens  texts      = World.EntityManager.GetComponentData <Childrens>(icon);
                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
                // experience required

                /*Entity textEntity2 = texts.children[1];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.experienceGained).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);
                 * // experience gained
                 * Entity textEntity3 = texts.children[2];
                 * RenderText renderText3 = World.EntityManager.GetComponentData<RenderText>(textEntity3);
                 * renderText3.SetText(((int)stat.experienceRequired).ToString());
                 * World.EntityManager.SetComponentData(textEntity3, renderText3);*/
            }
        }
示例#15
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            // spawn stat icon for each thing
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character);
            Stats stats = World.EntityManager.GetComponentData <Stats>(character);

            #region StatIcons
            List <Entity> statIcons = new List <Entity>();
            //List<Entity> statTexts = new List<Entity>();
            float2 iconSize = uiDatam.defaultIconSize;
            for (int i = 0; i < stats.stats.Length; i++)
            {
                if (meta.ContainsKey(stats.stats[i].id) == false)
                {
                    continue;
                }
                statIcons.Add(UIUtilities.SpawnButton(
                                  World.EntityManager,
                                  panelUI,
                                  float3.zero,
                                  iconSize,
                                  meta[stats.stats[i].id].texture.texture, uiDatam.defaultPlayerIcon));
                var textA = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                                                  ((int)stats.stats[i].value).ToString());//, iconSize);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.states.Length; i++)
            {
                if (meta.ContainsKey(stats.states[i].id) == false)
                {
                    continue;
                }
                statIcons.Add(UIUtilities.SpawnButton(
                                  World.EntityManager,
                                  panelUI,
                                  float3.zero,
                                  iconSize,
                                  meta[stats.states[i].id].texture.texture, uiDatam.defaultPlayerIcon));
                var textA = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                                                  ((int)stats.states[i].value).ToString());//,// iconSize,
                // new float3(0, iconSize.y / 2f, 0));
                //var textB = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                //                    ((int)stats.states[i].maxValue).ToString());//, iconSize);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                //children2.children[1] = textB;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.regens.Length; i++)
            {
                Entity icon = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    meta[stats.regens[i].id].texture.texture, uiDatam.defaultPlayerIcon);
                Entity textA = UIUtilities.SpawnText(World.EntityManager, icon, ((int)stats.regens[i].value).ToString());//, iconSize);
                statIcons.Add(icon);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.attributes.Length; i++)
            {
                Entity icon = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    meta[stats.attributes[i].id].texture.texture, uiDatam.defaultPlayerIcon);
                statIcons.Add(icon);
                var textA = UIUtilities.SpawnText(World.EntityManager, icon, ((int)stats.attributes[i].value).ToString());//, iconSize);
                //statTexts.Add(text);
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;
                World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2);
            }
            for (int i = 0; i < stats.levels.Length; i++)
            {
                Entity icon = UIUtilities.SpawnButton(
                    World.EntityManager,
                    panelUI,
                    float3.zero,
                    iconSize,
                    meta[stats.levels[i].id].texture.texture, uiDatam.defaultPlayerIcon);
                statIcons.Add(icon);
                var textA = UIUtilities.SpawnText(World.EntityManager, icon,
                                                  ((int)stats.levels[i].value).ToString());//, iconSize);

                /*var textB = UIUtilities.SpawnText(World.EntityManager, icon,
                 *                  ((int)stats.levels[i].experienceGained).ToString(),
                 *                  //iconSize,
                 *                  new float3(0, iconSize.y / 3, 0));
                 * var textC = UIUtilities.SpawnText(World.EntityManager, icon,
                 *                  ((int)stats.levels[i].experienceRequired).ToString(),
                 *                  //iconSize,
                 *                  new float3(0, 2 * iconSize.y / 3, 0));*/
                Childrens children2 = new Childrens {
                };
                children2.children    = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent);
                children2.children[0] = textA;

                /*children2.children[1] = textB;
                *  children2.children[2] = textC;*/
                World.EntityManager.AddComponentData(icon, children2);
            }
            #endregion
            Childrens children = new Childrens {
            };
            children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < statIcons.Count; i++)
            {
                children.children[i] = statIcons[i];
            }
            World.EntityManager.AddComponentData(panelUI, children);
            //float2 iconSize = new float2(uiDatam.skillbarIconSize, uiDatam.skillbarIconSize);
            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = uiDatam.statsUIGridSize,
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.003f, 0.003f),
            });
            byte uiIndex = ((byte)((int)PlayerUIType.StatsUI));
            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = zoxID.id,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            //characterStatUIs.Add(zoxID.id, CharacterStatUIData);
            //CreateSelected(character, panelUI, ((byte)PlayerUIType.StatsUI), iconSize);
            OnSelectedButton(zoxID.id, 0);
        }
示例#16
0
        private void ApplyDamage(Entity attacker, Entity defender, float damageDone)
        {
            // now get components
            if (!(World.EntityManager.HasComponent <Stats>(attacker) && World.EntityManager.HasComponent <Stats>(defender)))
            {
                return;
            }
            ZoxID       defenderID          = World.EntityManager.GetComponentData <ZoxID>(defender);
            Stats       defenderStats       = World.EntityManager.GetComponentData <Stats>(defender);
            ZoxID       attackerID          = World.EntityManager.GetComponentData <ZoxID>(attacker);
            Stats       attackerStats       = World.EntityManager.GetComponentData <Stats>(attacker);
            Translation defenderTranslation = World.EntityManager.GetComponentData <Translation>(defender);
            int         healthIndex         = 0;

            // decrease health
            if (defenderStats.states.Length == 0)
            {
                return; // cannot apply damage to gods
            }
            StateStaz healthStat = defenderStats.states[healthIndex];

            if (damageDone > 0 && healthStat.IsMaxValue())
            {
                // add regening to them
                RegenCompleterSystem.StartRegening(World.EntityManager, defender);
            }
            healthStat.value -= damageDone;
            //Debug.Log("Damage done: " + damageDone + " to " + defender.Index
            //    + " - " + defenderStats.states[0].value + " out of " + defenderStats.states[0].maxValue);
            if (healthStat.value < 0)
            {
                healthStat.value = 0;
            }
            defenderStats.states[healthIndex] = healthStat;
            // health pop up here
            damagePopupSystem.SpawnPopup(damageDone, defenderTranslation.Value);

            // Death
            if (healthStat.value == 0)// && defenderStats.isDead == 0)
            {
                //Debug.LogError("Defender ID has died: " + defender.Index + " at " + UnityEngine.Time.time);
                // Give rewards to Victor
                int metaID = 0;
                if (World.EntityManager.HasComponent <Character>(defender))
                {
                    metaID = World.EntityManager.GetComponentData <Character>(defender).metaID;
                }
                RewardVictor(ref defenderStats, attacker, ref attackerStats, defenderID.clanID,
                             metaID);
                defenderStats.willDie = 1;
                //defenderStats.timeDied = UnityEngine.Time.time;
                // Spawn Item
                //body.velocity = float3.zero;
                // give xp to attacker
            }
            else
            {
                // Attack back!
                RespondToAttack(defender, attacker);
                TriggerStatbar(defender, defenderID.id);
            }
            World.EntityManager.SetComponentData(defender, defenderStats);
        }
示例#17
0
        //public override void OnClickedButton(int characterID, int arrayIndex)
        //{
        //int originalArrayIndex = arrayIndex;
        //Entity character = characterSpawnSystem.characters[characterID];
        //Stats stats = World.EntityManager.GetComponentData<Stats>(character);
        //}

        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            // spawn stat icon for each thing
            ZoxID  zoxID  = World.EntityManager.GetComponentData <ZoxID>(character);
            Skills skills = World.EntityManager.GetComponentData <Skills>(character);

            #region StatIcons
            List <Entity> statIcons = new List <Entity>();
            //List<Entity> statTexts = new List<Entity>();
            float2 iconSize = uiDatam.defaultIconSize;

            for (int i = 0; i < skills.skills.Length; i++)
            {
                int metaID = skills.skills[i].id;
                if (meta.ContainsKey(metaID))
                {
                    statIcons.Add(UIUtilities.SpawnButton(
                                      World.EntityManager,
                                      panelUI,
                                      float3.zero,
                                      iconSize,
                                      meta[metaID].texture.texture, uiDatam.defaultPlayerIcon));
                    Childrens textLink = new Childrens {
                        children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent)
                    };
                    textLink.children[0] = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1],
                                                                 ((int)skills.skills[i].attackDamage).ToString()); //, iconSize);
                    World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], textLink);
                }
                else
                {
                    Debug.LogError("Trying to add meta id in StatsUI (Stats(" + i + ")) that doesn't exist: " + metaID);
                }
            }
            #endregion
            Childrens children = new Childrens {
            };
            children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < statIcons.Count; i++)
            {
                children.children[i] = statIcons[i];
            }
            World.EntityManager.AddComponentData(panelUI, children);
            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = uiDatam.inventoryGridSize,
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.003f, 0.003f),
            });
            byte uiIndex = ((byte)((int)PlayerUIType.SkillbookUI));
            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = zoxID.id,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            OnSelectedButton(zoxID.id, 0);
        }
示例#18
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            var position = World.EntityManager.GetComponentData <ChunkStreamPoint>(character).chunkPosition;
            //EntityBunch icons = new EntityBunch();
            List <Entity> icons2        = new List <Entity>();
            int           mapResolution = 4;

            if (Bootstrap.instance)
            {
                mapResolution = Bootstrap.instance.mapResolution;
            }
            int    rowsCount    = mapResolution;
            int    columnsCount = mapResolution;
            float2 iconSize     = uiDatam.defaultIconSize;

            //for (int j = -(columnsCount / 2); j < (columnsCount / 2); j++)
            for (int j = (columnsCount / 2) - 1; j >= -(columnsCount / 2); j--)
            {
                for (int i = -(rowsCount / 2); i < (rowsCount / 2); i++)
                {
                    float2 mapPosition = new float2(i + position.x, j + position.z);
                    if (chunkMapSystem.maps.ContainsKey(mapPosition))
                    {
                        float3 localMapPosition = float3.zero;// GetGridPosition(i + rowsCount / 2, -(j - (columnsCount / 2) + 1), rowsCount, columnsCount); // + columnsCount / 2
                        icons2.Add(UIUtilities.SpawnVisualElement(
                                       World.EntityManager,
                                       panelUI, localMapPosition,
                                       iconSize,
                                       chunkMapSystem.maps[mapPosition], uiDatam.mapIcon));
                    }
                    else
                    {
                        //Debug.LogError("Could not find map for positoin: " + mapPosition.ToString());
                    }
                }
            }
            Childrens children = new Childrens {
            };

            children.children = new BlitableArray <Entity>(icons2.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < icons2.Count; i++)
            {
                children.children[i] = icons2[i]; // icons2.Count - 1 -
            }
            World.EntityManager.AddComponentData(panelUI, children);
            World.EntityManager.AddComponentData(panelUI, new GridUI
            {
                dirty    = 1,
                gridSize = new float2(mapResolution, mapResolution),
                iconSize = iconSize,
                margins  = new float2(0.003f, 0.003f),
                padding  = new float2(0.00f, 0.00f),
            });
            byte  uiIndex     = ((byte)((int)PlayerUIType.SkillbookUI));
            ZoxID characterID = World.EntityManager.GetComponentData <ZoxID>(character);

            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = characterID.id,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });

            /*icons.entities = icons2.ToArray();;
             * if (mapIcons.ContainsKey(characterID.id))
             * {
             *  mapIcons.Remove(characterID.id);
             * // Debug.LogError("Map Icons in there twice for: " + characterID.id);
             * }
             * mapIcons.Add(characterID.id, icons);*/
        }