Beispiel #1
0
        public static State parseBytes(byte[] bytes)
        {
            Console.WriteLine("parseBytes" + (bytes != null ? "" + bytes.Length: "null"));
            byte[] part      = Utilities.SubArray <byte>(bytes, 0, sizeof(ushort) + 2 * sizeof(byte) + 2 * sizeof(int));
            int    idSkill   = BitConverter.ToUInt16(Utilities.SubArray <byte>(part, 0, sizeof(ushort)), 0);
            int    attacker  = bytes[0 + sizeof(ushort)];
            int    defender  = bytes[1 + sizeof(ushort)];
            int    healthAtt = BitConverter.ToInt32(Utilities.SubArray <byte>(part, sizeof(ushort) + 2, sizeof(int)), 0);
            int    healthDef = BitConverter.ToInt32(Utilities.SubArray <byte>(part, sizeof(ushort) + 2 + sizeof(int), sizeof(int)), 0);

            State state = new State(attacker, defender);

            state.healthPlayer1 = healthAtt;
            state.healthPlayer2 = healthDef;
            state.id            = idSkill;

            int byte_shift = sizeof(ushort) + 2 * sizeof(byte) + 2 * sizeof(int);

            while (byte_shift < bytes.Length)
            {
                int length = bytes[byte_shift];
                part = Utilities.SubArray <byte>(bytes, byte_shift, length + 1);
                NewEffect effect = NewEffect.parseBytes(part);
                state.effects.Add(effect);
                byte_shift += 1 + length;
            }
            return(state);
        }
Beispiel #2
0
        public AtomicEffect(NewEffect parent, string delta, string index, bool enemy, string condition, int duration = -1)
        {
            this.parent    = parent;
            this.delta     = delta;
            this.index     = index;
            this.enemy     = enemy;
            this.condition = condition;

            this.duration = duration;             // la round nen phai * 2
            if (condition != "")
            {
                enabled = false;
            }
            Console.WriteLine("create atomic with condition" + condition + " " + enabled);
        }
Beispiel #3
0
        public ArrayList affect(NewCharacterStatus attStatus, NewCharacterStatus defStatus)
        {
            bool   me       = false;
            bool   you      = false;
            string name     = data["name"].Value;
            string nick     = data["nick"].Value;
            int    level    = Convert.ToInt32(data["level"].Value);
            int    duration = data["duration"] == null? -1 :  Convert.ToInt32(data["duration"].Value);

            string    condition = data["condition"] == null ? "" : data["condition"].Value;
            NewEffect effect    = new NewEffect(attStatus.playerID, name, nick, level, 2 * duration, condition); // vi tinh theo turn

            if (condition != "")
            {
                ArrayList enableSkills = attStatus.enableSkills.ContainsKey(condition) ? attStatus.enableSkills[condition] : new ArrayList();
                enableSkills.Add(effect);
                attStatus.enableSkills.Add(condition, enableSkills);
            }

            JSONArray lines = (JSONArray)data["lines"];

            foreach (JSONObject line in lines)
            {
                string delta = line["delta"].Value;
                string index = line["index"].Value;
                string con   = line["condition"] == null ? "" : line["condition"].Value;
                bool   enemy = line["enemy"] == null ? false : Convert.ToBoolean(line["enemy"].Value);
                duration = line["duration"] == null ? -1 : Convert.ToInt32(line["duration"].Value);
                AtomicEffect       atomic       = new AtomicEffect(effect, delta, index, enemy, con, duration);
                NewCharacterStatus targetStatus = null;
                if (enemy)
                {
                    targetStatus = defStatus;
                    // them effect vao danh sach effect
                    // them danh sach atmoic
                    // them danh sach fomula
                    you = true;
                }
                else
                {
                    targetStatus = attStatus;
                    me           = true;
                }

                //targetStatus.replaceEffect(name, effect);

                ArrayList atomics = targetStatus.atomics.ContainsKey(index) ? targetStatus.atomics[index] : new ArrayList();
                atomics.Add(atomic);
                targetStatus.atomics.Add(index, atomics);

                effect.atomicEffects.Add(atomic);
                // tinh lai cong thuc
                //ArrayList formulas = defStatus.formulas.ContainsKey(index) ? defStatus.formulas[index] : new ArrayList();
                //string formulas = !targetStatus.deltaFormulas.ContainsKey(index) ? "" : targetStatus.deltaFormulas[index] + " + ";
                //formulas += delta;
                //targetStatus.deltaFormulas.Add(index, formulas);

                if (con != "")
                {
                    // them vao danh sach dieu kien
                    ArrayList enableAtomics = targetStatus.enableAtomics.ContainsKey(con) ? targetStatus.enableAtomics[con] : new ArrayList();
                    enableAtomics.Add(atomic);
                    targetStatus.enableAtomics.Add(con, enableAtomics);
                }
            }
            int playerID = 0;

            if (me && you)
            {
                playerID = attStatus.playerID + defStatus.playerID;
            }
            else if (me)
            {
                playerID = attStatus.playerID;
            }
            else if (you)
            {
                playerID = defStatus.playerID;
            }


            //NewEffect clone = effect.clone();
            effect.playerID = playerID;

            if (me)
            {
                attStatus.replaceEffect(name, effect);
            }
            if (you)
            {
                defStatus.replaceEffect(name, effect);
            }
            // parse Special Atomics
            effect.parseAtomics(attStatus, defStatus);


            ArrayList result = new ArrayList();

            result.Add(effect);

            return(result);
        }
Beispiel #4
0
        public NewEffect parseString(string base64string) // Convert ra NewEffect chua ket noi voi cac Status
        {
            NewEffect effect = null;

            byte[] bytes = Convert.FromBase64String(base64string);
            bytes = Utilities.SubArray <byte>(bytes, 1, bytes.Length - 1);            // loai bo byte file do dai day byte


            int byte_shift = 0;
            int sub        = 0;

            byte[] part = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(ushort));
            ushort type = BitConverter.ToUInt16(part, 0);

            byte_shift += sizeof(ushort);

            part        = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(byte));
            byte_shift += sizeof(byte);
            int originID = part[0];

            string name = "";
            string nick = "";

            part        = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(byte));
            byte_shift += sizeof(byte);
            int playerID = part[0];

            if (type < 1000)             // SKill
            {
                NewSkill skill = Adapter.skills["Skill" + type];
                nick = "Skill" + type;
                name = skill.data["name"].Value;
                // doc tiep
                part        = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(byte));
                byte_shift += sizeof(byte);
                int level = (sbyte)part[0];
                // duration
                part        = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(byte));
                byte_shift += sizeof(byte);
                int duration = (sbyte)part[0];
                // doc tiep cac atomic

                string condition = skill.data["condition"] == null ? "" : skill.data["condition"].Value;
                effect = new NewEffect(originID, name, nick, level, duration, condition);

                JSONNode data = skill.data;

                JSONArray lines = (JSONArray)data["lines"];

                foreach (JSONObject line in lines)
                {
                    part        = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(byte));
                    byte_shift += sizeof(byte);
                    duration    = (sbyte)part[0];

                    string       delta  = line["delta"].Value;
                    string       index  = line["index"].Value;
                    string       con    = line["condition"] == null ? "" : line["condition"].Value;
                    bool         enemy  = line["enemy"] == null ? false : Convert.ToBoolean(line["enemy"].Value);
                    AtomicEffect atomic = new AtomicEffect(effect, delta, index, enemy, con, duration);
                    effect.atomicEffects.Add(atomic);
                }

                effect.playerID = playerID;
            }
            else if (type < 2000)             // AS
            {
                sub = type - 1000;
                AbnormalStatus ab = Adapter.abs["AS" + type];
                nick = "AS" + type;
                name = ab.data["name"].Value;

                part        = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(byte));
                byte_shift += sizeof(byte);
                int duration = (sbyte)part[0];
                effect = new NewEffect(originID, name, nick, -1, duration);
                JSONNode data = ab.data;

                JSONArray lines = data["line"] != null ? (JSONArray)data["lines"] : null;
                if (lines != null)
                {
                    foreach (JSONObject line in lines)
                    {
                        part        = Utilities.SubArray <byte>(bytes, byte_shift, sizeof(byte));
                        byte_shift += sizeof(byte);
                        duration    = (sbyte)part[0];
                        string       delta  = line["delta"].Value;
                        string       index  = line["index"].Value;
                        string       con    = line["condition"] == null ? "" : line["condition"].Value;
                        bool         enemy  = true;
                        AtomicEffect atomic = new AtomicEffect(effect, delta, index, enemy, con, duration);
                        effect.atomicEffects.Add(atomic);
                    }
                }
                switch (name)
                {
                case Burn:
                    part = Utilities.SubArray <byte>(bytes, byte_shift, bytes.Length - byte_shift);
                    effect.indexes.Add("burn_damage", BitConverter.ToInt32(part, 0));
                    break;

                case Poisoning:
                    part = Utilities.SubArray <byte>(bytes, byte_shift, bytes.Length - byte_shift);
                    effect.indexes.Add("poison_damage", BitConverter.ToInt32(part, 0));
                    break;
                }

                effect.playerID = playerID;
            }
            else
            {
                sub = type - 2000;
                switch (sub)
                {
                case 1:
                    effect = new NewEffect(originID, "HealthChanges");
                    break;

                case 2:
                    effect = new NewEffect(originID, "Blocking");

                    break;

                case 3:
                    effect = new NewEffect(originID, "Dodge");

                    break;

                case 4:
                    effect = new NewEffect(originID, "Critical");

                    break;

                case 5:
                    effect = new NewEffect(originID, "ReturnDamage");
                    break;

                case 6:
                    effect = new NewEffect(originID, "Multicast");
                    break;

                case 7:
                    effect = new NewEffect(originID, "RemoveAllAbnormal");
                    break;

                case 8:
                    effect = new NewEffect(originID, "DoubleMagic");
                    break;

                case 9:
                    effect = new NewEffect(originID, "HealthRecovery");
                    break;

                case 10:
                    effect = new NewEffect(originID, "HealthRecovery_Glamour");
                    break;

                default:
                    if (sub < 4000)
                    {    // HealthAdd_Skill
                        effect = new NewEffect(originID, "HealthAdd_Skill" + (sub - 3000));
                    }
                    else if (sub < 5000)
                    {    // HealthAdd_Glamour_Skill
                        effect = new NewEffect(originID, "HealthAdd_Glamour_Skill" + (sub - 4000));
                    }
                    else if (sub < 6000)
                    {
                        effect = new NewEffect(originID, "HealthSub_Skill" + (sub - 5000));
                    }
                    break;
                }
                effect.playerID = playerID;
            }


            return(effect);
        }