Ejemplo n.º 1
0
        public Character(System.IO.BinaryReader reader, bool sentFromServer)
            : base(reader, sentFromServer)
        {
            myHitPoints = reader.ReadInt16();
            myManaLevel = reader.ReadInt16();

            ushort attribCount = reader.ReadUInt16();

            for (int i = 0; i < attribCount; ++i)
            {
                myBaseAttributes.Add(CharAttribute.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            ushort skillCount = reader.ReadUInt16();

            for (int i = 0; i < skillCount; ++i)
            {
                myBaseSkills.Add(CharSkill.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            myCurrentWalkDirection = myFacingDirection = (WalkDirection)reader.ReadByte();

            if (!sentFromServer)
            {
                Inventory = new Inventory(this, reader);
            }
        }
Ejemplo n.º 2
0
 public SkillRow(Vector2 position, CharSkill skill, CharacterCreationOutput output)
     : base(Font.Large, position)
 {
     myOutput = output;
     mySkill  = skill;
     Refresh();
 }
Ejemplo n.º 3
0
        private void ReceiveCharacterCreate(BinaryReader reader)
        {
            Nickname = reader.ReadString();

            PlayerEntity = new Player();

            ushort attribCount = reader.ReadUInt16();

            for (int i = 0; i < attribCount; ++i)
            {
                CharAttribute attrib = CharAttribute.GetByID(reader.ReadUInt16());
                int           value  = reader.ReadByte();

                PlayerEntity.SetBaseAttributeLevel(attrib, value);
            }

            ushort skillCount = reader.ReadUInt16();

            for (int i = 0; i < skillCount; ++i)
            {
                CharSkill skill = CharSkill.GetByID(reader.ReadUInt16());
                int       value = reader.ReadByte();

                PlayerEntity.SetBaseSkillLevel(skill, value);
            }

            SendCharacterCreate();
        }
    protected override void OnHandleEvent(IEventMessage msg)
    {
        if (msg is BattleEvent.DamageHurt)
        {
            if (CharData.IsDead == false)
            {
                BattleEvent.DamageHurt message = msg as BattleEvent.DamageHurt;
                CharData.DamageHurt(message.Damage);
                CharAnim.Play("getHit");

                // 随机播放角色受击音效
                string soundName = Avatar.GetRandomGetHitSound();
                if (string.IsNullOrEmpty(soundName) == false)
                {
                    AudioManager.Instance.PlaySound(soundName);
                }
            }
        }
        else if (msg is BattleEvent.CharacterDead)
        {
            CharSkill.ForbidAll();
            CharAnim.Play("die");

            // 播放角色死亡音效
            string soundName = Avatar.GetDeadSound();
            if (string.IsNullOrEmpty(soundName) == false)
            {
                AudioManager.Instance.PlaySound(soundName);
            }
        }
    }
Ejemplo n.º 5
0
    protected override void OnHandleEvent(IEventMessage msg)
    {
        base.OnHandleEvent(msg);

        if (msg is BattleEvent.PlayerSpell)
        {
            BattleEvent.PlayerSpell message = msg as BattleEvent.PlayerSpell;
            CharSkill.Spell(message.SkillID);
        }
    }
Ejemplo n.º 6
0
        public int GetSkillLevel(CharSkill skill, bool includeMagicalEffects = true)
        {
            int val = GetBaseSkillLevel(skill);

            foreach (KeyValuePair <CharAttribute, double> keyVal in skill.AttributeMods)
            {
                val += (int)Math.Round(GetAttributeLevel(keyVal.Key, includeMagicalEffects) * keyVal.Value);
            }

            return(val);
        }
Ejemplo n.º 7
0
        public int GetTotalSkillPoints(CharSkill skill)
        {
            int points = GetBaseSkillPoints(skill);

            foreach (KeyValuePair <CharAttribute, double> keyVal in skill.AttributeMods)
            {
                points += (int)(GetAttributePoints(keyVal.Key) * keyVal.Value);
            }

            return(points);
        }
Ejemplo n.º 8
0
        public CharacterCreationOutput(int baseAttributePoints, int baseSkillPoints)
        {
            PlayerName       = "Player";
            myBaseAttributes = new Dictionary <CharAttribute, int>();
            myBaseSkills     = new Dictionary <CharSkill, int>();

            foreach (CharAttribute attrib in CharAttribute.GetAll())
            {
                myBaseAttributes.Add(attrib, baseAttributePoints);
            }

            foreach (CharSkill skill in CharSkill.GetAll())
            {
                myBaseSkills.Add(skill, baseSkillPoints);
            }
        }
Ejemplo n.º 9
0
    protected override void OnUpdate(float deltaTime)
    {
        base.OnUpdate(deltaTime);

        if (UIJoystick.Joystick != null)
        {
            if (CharSkill.IsAnyLife())
            {
                return;
            }
            if (UIJoystick.Joystick.IsDragging)
            {
                Vector2 joyAxis = UIJoystick.Joystick.JoystickAxis;
                Vector3 joyDir  = Camera.main.transform.forward * joyAxis.y + Camera.main.transform.right * joyAxis.x;
                CharMove.BeginJoyMove(joyDir);
            }
        }
    }
Ejemplo n.º 10
0
        public void SetBaseSkillLevel(CharSkill skill, int amount)
        {
            amount = Tools.Clamp(amount, 0, 50);

            if (!myBaseSkills.ContainsKey(skill))
            {
                myBaseSkills.Add(skill, amount);
            }
            else
            {
                myBaseSkills[skill] = amount;
            }

            if (Map != null && IsServer)
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                stream.Write(BitConverter.GetBytes(skill.ID), 0, 2);
                stream.WriteByte((byte)amount);
                SendStateUpdate("SetBaseSkill", stream);
                stream.Close();
            }
        }
Ejemplo n.º 11
0
        public void SendCharacterCreate(CharacterCreationOutput output)
        {
            myClients[GameClient.ID].Nickname = output.PlayerName;

            BinaryWriter writer = GetWriter();

            writer.Write((byte)PacketID.CharacterCreate);
            writer.Write(output.PlayerName);
            writer.Write((ushort)CharAttribute.GetAll().Length);
            foreach (CharAttribute attrib in CharAttribute.GetAll())
            {
                writer.Write(attrib.ID);
                writer.Write((byte)output.GetAttributePoints(attrib));
            }
            writer.Write((ushort)CharSkill.GetAll().Length);
            foreach (CharSkill skill in CharSkill.GetAll())
            {
                writer.Write(skill.ID);
                writer.Write((byte)output.GetBaseSkillPoints(skill));
            }

            SendPacket();
        }
    protected override void OnUpdateAvatar(float deltaTime)
    {
        if (CharSkill.IsAnyLife())
        {
            return;
        }

        if (CharMove.IsMoving)
        {
            float animSpeed = CharData.MoveSpeed / Avatar.GetRunAnimationSpeed();
            CharAnim.SetSpeed(CharData.CurrentRunAnimName, animSpeed);
            if (CharAnim.IsPlaying(CharData.CurrentRunAnimName) == false)
            {
                CharAnim.Play(CharData.CurrentRunAnimName, 0.15f);
            }
        }
        else
        {
            if (CharAnim.IsPlaying(CharData.CurrentIdleAnimName) == false)
            {
                CharAnim.Play(CharData.CurrentIdleAnimName, 0.15f);
            }
        }
    }
Ejemplo n.º 13
0
        public AttributeCreation(CharacterCreation parent, CharacterCreationOutput output)
        {
            myParent = parent;
            myOutput = output;



            float y = 4;

            myPointsLabel = new UILabel(Font.Large, new Vector2(4, y));
            AddChild(myPointsLabel);
            UnusedPoints = GameClient.CharacterUnusedAttribPoints;

            y += 30;

            foreach (CharAttribute attrib in CharAttribute.GetAll())
            {
                var row = new AttribRow(this, attrib, myOutput);
                row.Top  = y;
                row.Left = 4;
                y       += 30;
                AddChild(row);
            }

            y += 20;

            var skills = CharSkill.GetAll();

            skillRows = new SkillRow[skills.Length];

            int i = 0;

            foreach (CharSkill skill in skills)
            {
                var row = new SkillRow(new Vector2(4, y), skill, myOutput);
                y           += 25;
                skillRows[i] = row;
                i++;
                AddChild(row);
            }

            var button = new UIButton(new Vector2(150, 20), new Vector2(300 - 150 - 4, y))
            {
                Text       = "Create Character",
                CentreText = true
            };

            AddChild(button);
            button.Click += new MouseButtonEventHandler(button_Click);

            var back = new UIButton(new Vector2(50, 20), new Vector2(4, y))
            {
                Text       = "Back",
                CentreText = true
            };

            back.Click += new MouseButtonEventHandler(back_Click);
            AddChild(back);

            y += 20;

            Width  = 300;
            Height = y + 4 + PaddingTop + PaddingBottom;
        }
Ejemplo n.º 14
0
 public int GetBaseSkillLevel(CharSkill skill)
 {
     return(myBaseSkills.ContainsKey(skill) ? myBaseSkills[skill] : 0);
 }
Ejemplo n.º 15
0
 public int GetBaseSkillPoints(CharSkill skill)
 {
     return(myBaseSkills[skill]);
 }
Ejemplo n.º 16
0
        protected override void OnRegisterNetworkedUpdateHandlers()
        {
            base.OnRegisterNetworkedUpdateHandlers();

            RegisterNetworkedUpdateHandler("StartWalking", delegate(byte[] payload)
            {
                StartWalking(
                    (WalkDirection)payload[0],
                    BitConverter.ToUInt64(payload, 1),
                    new Vector2d(
                        BitConverter.ToDouble(payload, 1 + sizeof(UInt64)),
                        BitConverter.ToDouble(payload, 1 + sizeof(UInt64) + sizeof(Double))
                        )
                    );
            });

            RegisterNetworkedUpdateHandler("StopWalking", delegate(byte[] payload)
            {
                StopWalking(
                    new Vector2d(BitConverter.ToDouble(payload, 0),
                                 BitConverter.ToDouble(payload, sizeof(Double))
                                 )
                    );
            });

            RegisterNetworkedUpdateHandler("SpellCast", delegate(byte[] payload)
            {
                Cast();
            });

            RegisterNetworkedUpdateHandler("SetHitPoints", delegate(byte[] payload)
            {
                HitPoints = BitConverter.ToInt32(payload, 0);
            });

            RegisterNetworkedUpdateHandler("Die", delegate(byte[] payload)
            {
                uint attackerID       = BitConverter.ToUInt32(payload, 0);
                uint weaponID         = BitConverter.ToUInt32(payload, 4);
                DamageType damageType = (DamageType)BitConverter.ToUInt16(payload, 6);

                Entity attacker = null;
                Entity weapon   = null;

                if (attackerID != 0xFFFFFFFF)
                {
                    attacker = Map.GetEntity(attackerID);
                }

                if (weaponID != 0xFFFFFFFF)
                {
                    weapon = Map.GetEntity(weaponID);
                }

                OnDie(attacker, weapon, damageType);

                if (Killed != null)
                {
                    Killed(this, new KilledEventArgs(attacker, weapon, damageType));
                }
            });

            RegisterNetworkedUpdateHandler("Resurrect", delegate(byte[] payload) {
                Resurrect();
            });

            RegisterNetworkedUpdateHandler("SetManaLevel", delegate(byte[] payload)
            {
                ManaLevel = BitConverter.ToInt32(payload, 0);
            });

            RegisterNetworkedUpdateHandler("SetBaseAttribute", delegate(byte[] payload)
            {
                UInt16 id   = BitConverter.ToUInt16(payload, 0);
                byte amount = payload[2];

                SetBaseAttributeLevel(CharAttribute.GetByID(id), amount);
            });

            RegisterNetworkedUpdateHandler("SetBaseSkill", delegate(byte[] payload)
            {
                UInt16 id   = BitConverter.ToUInt16(payload, 0);
                byte amount = payload[2];

                SetBaseSkillLevel(CharSkill.GetByID(id), amount);
            });

            RegisterNetworkedUpdateHandler("EquipSpell", delegate(byte[] payload)
            {
                MemoryStream stream = new MemoryStream(payload);
                BinaryReader reader = new BinaryReader(stream);
                myEquippedSpell     = Spell.Create(SpellInfo.Get(reader.ReadUInt16()), reader.ReadDouble());
                myOrbEquipped       = reader.ReadBoolean();
                reader.Close();
            });

            RegisterNetworkedUpdateHandler("UnEquipSpell", delegate(byte[] payload)
            {
                myEquippedSpell = null;
                myOrbEquipped   = false;
            });
        }
Ejemplo n.º 17
0
        public CharAttribDisplay(Character character)
        {
            Title = "Attributes and Skills";

            String str = "Attributes:";

            foreach (CharAttribute attrib in CharAttribute.GetAll())
            {
                String line = "\n  " + attrib.ToString();

                int baseVal = character.GetAttributeLevel(attrib, false);
                int currVal = character.GetAttributeLevel(attrib, true);
                int diff    = currVal - baseVal;

                while (line.Length < 20)
                {
                    line += " ";
                }

                line += ": " + currVal.ToString();

                while (line.Length < 26)
                {
                    line += " ";
                }

                line += "(" + (diff > 0 ? "+" : "") + diff.ToString() + ")";

                str += line;
            }

            str += "\n\nSkills:";
            foreach (CharSkill skill in CharSkill.GetAll())
            {
                String line = "\n  " + skill.ToString();

                int baseVal = character.GetSkillLevel(skill, false);
                int currVal = character.GetSkillLevel(skill, true);
                int diff    = currVal - baseVal;

                while (line.Length < 20)
                {
                    line += " ";
                }

                line += ": " + currVal.ToString();

                while (line.Length < 26)
                {
                    line += " ";
                }

                line += "(" + (diff > 0 ? "+" : "") + diff.ToString() + ")";

                str += line;
            }

            str += "\n\nHit Points: " + character.HitPoints + "/" + character.MaxHitPoints;
            str += "\nMana Level: " + character.ManaLevel + "/" + character.MaxManaLevel;
#if DEBUG
            str += "\nWalk Speed: " + character.WalkSpeed.ToString("F");
            str += "\nMana Regen: " + character.ManaRechargePeriod.ToString("F");
            str += "\nCast Delay: " + character.CastCooldownTime.ToString("F");
            str += "\nHeal Delay: " + character.FastHPRechargeDelay.ToString("F");
#endif

            myText = new UILabel(Font.Large)
            {
                Text     = str,
                Position = new Vector2(4, 4)
            };
            AddChild(myText);

            Width  = myText.Width + 8 + PaddingLeft + PaddingRight;
            Height = myText.Height + 8 + PaddingTop + PaddingBottom;
        }
Ejemplo n.º 18
0
    // Updates the Skill System UI Elements every frame */
    void Update()
    {
        /* If Skill Data has not been loaded, load data  */
        if (this.getSkillDataSourceLoaded() == false)
        {
            /* Checks to see if Skill Data is ready to be loaded */
            if (this.skillDataSource.getSkillDataLoaded() == true)
            {
                /* Loads Skill data */
                for (int i = 0; i < this.charSkills.Length; i++)
                {
                    charSkills[i] = new CharSkill(this.skillDataSource.getSkillListID()[i],
                                                  this.skillDataSource.getSkillListName()[i],
                                                  this.skillDataSource.getSkillListDescription()[i],
                                                  this.skillDataSource.getSkillListType()[i],
                                                  this.skillDataSource.getSkillListTier()[i],
                                                  this.skillListIcon[i],
                                                  this.skillDataSource.getSkillListCooldown()[i]);
                }

                /* Indicate that Skill Data has been loaded */
                this.setSkillDataSourceLoaded(true);
            }
        }

        /* Otherwise, Skill System is active */
        else
        {
            /* Updates the cooldown status for each Skill */
            for (int i = 0; i < this.getNumSkillSlots(); i++)
            {
                /* Checks to see if Skill Slot currently has an Active skill */
                if (this.skillSlots[i].getSlotSkill().getSkillType() == 1)
                {
                    /* Checks to see if cooldown period of Skill is active */
                    if (this.skillSlots[i].getSlotSkill().getSkillCooldownElapsed() < this.skillSlots[i].getSlotSkill().getSkillCooldownTotal())
                    {
                        this.skillSlots[i].getSlotSkill().setCooldownPeriodActive(true);                                                                                                         // Sets the Cooldown Period of the Skill as active
                        this.skillSlots[i].getSlotSkill().setSkillCooldownElapsed(this.skillSlots[i].getSlotSkill().getSkillCooldownElapsed() + Time.deltaTime);                                 // Increments the elapsed cooldown period
                        this.skillSlots[i].getSlotObject().fillAmount = this.skillSlots[i].getSlotSkill().getSkillCooldownElapsed() / this.skillSlots[i].getSlotSkill().getSkillCooldownTotal(); // Sets the countdown indicator for the Skill Slot
                    }

                    /* If cooldown period is not active */
                    else
                    {
                        this.skillSlots[i].getSlotSkill().setCooldownPeriodActive(false);  // Sets the Cooldown Period of the Skill as inactive
                    }
                }

                /* Updates the Skill Info Box to display the Player's current Skills */

                /* Retrieves and populates text objects with Skill attributes */
                this.skillInfoObjects[i].text = ("SLOT " + (i + 1) + ":   " + this.skillSlots[i].getSlotSkill().getSkillName() + " - " + this.skillSlots[i].getSlotSkill().getSkillDescription());
            }
        }

        /* Detects whether user has pressed the Skill Info Box key */
        if (Input.GetKeyDown(KeyCode.I))
        {
            /* Checks to see if the Skill Info Box is currently visible */
            if (this.skillInfoBoxObject.GetActive() == false)  // If not visible
            {
                this.skillInfoBoxObject.SetActive(true);
            }
            else  // If visible
            {
                this.skillInfoBoxObject.SetActive(false);
            }
        }
    }
Ejemplo n.º 19
0
 /* Sets the Skill currently assigned to the Skill Slot */
 public void setSlotSkill(CharSkill currentSkill)
 {
     this.currentSkill = currentSkill;
 }
 protected override void OnUpdate(float deltaTime)
 {
     CharData.Update(deltaTime);
     CharSkill.Update(deltaTime);
     CharMove.Update(deltaTime);
 }