Пример #1
0
        static CallbackResult OnSkillsUpdate(byte[] data, CallbackResult prevResult)
        {
            lock (syncRoot) {
                PacketReader reader = new PacketReader(data);
                byte         id     = reader.ReadByte();
                if (id != 0x3A)
                {
                    throw new Exception("Invalid packet passed to OnSkillsUpdate.");
                }

                ushort packetLenght = reader.ReadUInt16();
                byte   type         = reader.ReadByte();

                bool skillcup = (type == 0x02) || (type == 0x03) || (type == 0xDF);
                bool loop     = (type != 0xDF && type != 0xFF);
                int  @base    = (loop ? 1 : 0); // For some strange reason, list has base 1 for skillid, and update 0.

                ushort lastID;

                // Loop only one time if Type is 0xFF, otherwise loop until SkillID is zero.
                while (reader.Offset < reader.Length && (lastID = reader.ReadUInt16()) > 0)
                {
                    SkillValue value = new SkillValue();
                    value.ID        = (ushort)(lastID - @base);
                    value.Value     = reader.ReadUInt16();
                    value.RealValue = reader.ReadUInt16();
                    value.Lock      = (SkillLock)reader.ReadByte();
                    value.MaxValue  = skillcup ? reader.ReadUInt16() : (ushort)0xFFFF; // TODO

                    Trace.WriteLine(String.Format("Received skill {0} update to {1}", value.ID, value.RealValue), "World");
                    OnSkillChanged(value);

                    // Stop iteration
                    if (!loop)
                    {
                        break;
                    }
                }

                return(CallbackResult.Normal);
            }
        }
Пример #2
0
        private static void OnSkillChanged(SkillValue value)
        {
            try {
                SkillValue oldValue;
                skillList.TryGetValue(value.ID, out oldValue);

                if (!value.Equals(oldValue))
                {
                    Trace.WriteLine("New value for skill", "World");
                    skillList[value.ID] = value;

                    skillChanged.Invoke(null, new SkillChangedEventArgs(value, oldValue));
                }
                else
                {
                    Trace.WriteLine("No new value for skill", "World");
                }
            }
            catch (Exception e) {
                Trace.WriteLine("Unhandled exception in PlayerSkills.SkillChanged event. Exception:\n" + e.ToString(), "World");
            }
        }
Пример #3
0
 public SkillChangedEventArgs(SkillValue value, SkillValue oldValue)
 {
     this.value    = value;
     this.oldValue = oldValue;
 }
Пример #4
0
 public bool Equals(SkillValue value)
 {
     return(value.ID == ID && value.Value == Value && value.RealValue == RealValue && value.Lock == Lock && value.MaxValue == MaxValue);
 }