Esempio n. 1
0
        public GroupCommand <TKey, ReadableTuple <TKey> > Generate <TKey>(ReadableTuple <TKey> item, ReadableTuple <int> tupleSource, AbstractDb <int> mobDb1, AbstractDb <int> mobDb2, AbstractDb <int> pet1, AbstractDb <int> pet2)
        {
            var description = item.GetValue <ParameterHolder>(ClientItemAttributes.Parameters).Values[ParameterHolderKeys.Description] ?? "";

            description = ParameterHolder.ClearDescription(description);

            ParameterHolder holder = new ParameterHolder();
            GroupCommand <TKey, ReadableTuple <TKey> > commands = GroupCommand <TKey, ReadableTuple <TKey> > .Make();

            int numSlotC = _getInt(ClientItemAttributes.NumberOfSlots, item);
            int numSlotS = _getInt(ServerItemAttributes.NumberOfSlots, tupleSource);

            if (ProjectConfiguration.AutocompleteViewId)
            {
                int viewIdC = _getInt(ClientItemAttributes.ClassNumber, item);
                int viewIdS = _getInt(ServerItemAttributes.ClassNumber, tupleSource);

                if (viewIdC != viewIdS)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.ClassNumber, viewIdS));
                }
            }

            if (ProjectConfiguration.AutocompleteNumberOfSlot)
            {
                if (numSlotC != numSlotS)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.NumberOfSlots, numSlotS));
                }
            }

            if ((TypeType)tupleSource.GetValue <int>(ServerItemAttributes.Type) != TypeType.Card)
            {
                if (item.GetValue <bool>(ClientItemAttributes.IsCard))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.IsCard, false));
                }
            }

            string idDisplayName = tupleSource.GetValue <string>(ServerItemAttributes.Name);

            if (_emptyFill(ClientItemAttributes.IdentifiedDisplayName, item) && ProjectConfiguration.AutocompleteIdDisplayName && _isNotNullDifferent(idDisplayName, ClientItemAttributes.IdentifiedDisplayName, item))
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.IdentifiedDisplayName, idDisplayName));
            }

            DbAttribute attribute;
            TypeType    itemType = (TypeType)tupleSource.GetValue <int>(ServerItemAttributes.Type);

            if (itemType == TypeType.Weapon || itemType == TypeType.Armor)
            {
                if (itemType == TypeType.Armor && !ItemParser.IsArmorType(tupleSource))
                {
                    if (itemType == TypeType.Armor)
                    {
                        itemType = TypeType.Weapon;
                    }
                    else
                    {
                        itemType = TypeType.Armor;
                    }
                }
            }

            // Weight:
            //holder = item.GetValue<ParameterHolder>(ClientItemAttributes.Parameters);
            //
            //switch (itemType) {
            //	case TypeType.Weapon:
            //	case TypeType.Ammo:
            //	case TypeType.Armor:
            //	case TypeType.Card:
            //	case TypeType.PetEgg:
            //	case TypeType.PetEquip:
            //	case TypeType.UsableItem:
            //	case TypeType.EtcItem:
            //	case TypeType.HealingItem:
            //	case TypeType.ShadowEquip:
            //	case TypeType.UsableWithDelayed:
            //	case TypeType.UsableWithDelayed2:
            //		_autoAddWeight(tupleSource, holder);
            //		break;
            //}

            DbAttribute equipLevelAttribute = ServerItemAttributes.EquipLevel;

            if (tupleSource.GetIntNoThrow(ServerItemAttributes.EquipLevelMin) > tupleSource.GetIntNoThrow(ServerItemAttributes.EquipLevel))
            {
                equipLevelAttribute = ServerItemAttributes.EquipLevelMin;
            }

            switch (itemType)
            {
            case TypeType.Weapon:
                string type = _findWeaponType(tupleSource) ?? "Weapon";
                holder.Values[ParameterHolderKeys.Class] = type;

                string unidentifiedResourceName = EncodingService.FromAnyToDisplayEncoding(_findWeaponUnidentifiedResource(tupleSource) ?? "");
                attribute = ClientItemAttributes.UnidentifiedResourceName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }

                string identifiedResourceName = item.GetStringValue(ClientItemAttributes.IdentifiedResourceName.Index);
                attribute = ClientItemAttributes.IdentifiedResourceName;
                if (String.IsNullOrEmpty(identifiedResourceName) && ProjectConfiguration.AutocompleteIdResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }

                attribute = ClientItemAttributes.UnidentifiedDisplayName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnDisplayName && _isNotNullDifferent(type, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, type));
                }

                if (!tupleSource.GetValue <bool>(ServerItemAttributes.Refineable))
                {
                    if (!description.Contains("Impossible to refine") &&
                        !description.Contains("Cannot be upgraded") &&
                        !description.ToLower().Contains("rental item"))
                    {
                        description += "\r\nImpossible to refine this item.";
                    }
                }

                if (tupleSource.GetValue <bool>(ServerItemAttributes.Refineable))
                {
                    if (description.Contains("Impossible to refine"))
                    {
                        description = description.Replace("Impossible to refine this item.", "").Trim('\r', '\n');
                    }
                }

                _autoAdd(ServerItemAttributes.Attack, ParameterHolderKeys.Attack, tupleSource, holder);
                _autoAddWeight(tupleSource, holder);
                _autoAdd(ServerItemAttributes.WeaponLevel, ParameterHolderKeys.WeaponLevel, tupleSource, holder);
                _autoAddJob(tupleSource, holder, _getInt(equipLevelAttribute, tupleSource));
                _autoAddElement(tupleSource, holder);
                break;

            case TypeType.Ammo:
                type = _findAmmoType(tupleSource.GetStringValue(ServerItemAttributes.ApplicableJob.Index)) ?? "Ammunition";
                holder.Values[ParameterHolderKeys.Class] = type;

                _autoAdd(ServerItemAttributes.Attack, ParameterHolderKeys.Attack, tupleSource, holder, -1);
                _autoAddWeight(tupleSource, holder);
                _autoAddElement(tupleSource, holder);
                break;

            case TypeType.Armor:
                int location = _getInt(ServerItemAttributes.Location, tupleSource);
                type = _findArmorType(location) ?? "Armor";
                holder.Values[ParameterHolderKeys.Class] = type;

                unidentifiedResourceName = EncodingService.FromAnyToDisplayEncoding(_findArmorUnidentifiedResource(tupleSource, item) ?? "");
                attribute = ClientItemAttributes.UnidentifiedResourceName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }
                else
                {
                    unidentifiedResourceName = item.GetValue <string>(ClientItemAttributes.UnidentifiedResourceName);
                }

                identifiedResourceName = item.GetStringValue(ClientItemAttributes.IdentifiedResourceName.Index);
                attribute = ClientItemAttributes.IdentifiedResourceName;
                if (String.IsNullOrEmpty(identifiedResourceName) && ProjectConfiguration.AutocompleteIdResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }

                string unDisplayName = _findArmorUnidentifiedDisplayName(unidentifiedResourceName);
                attribute = ClientItemAttributes.UnidentifiedDisplayName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnDisplayName && _isNotNullDifferent(unDisplayName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unDisplayName));
                }

                if ((_getInt(ServerItemAttributes.Location, tupleSource) & 374) != 0)
                {
                    if (!tupleSource.GetValue <bool>(ServerItemAttributes.Refineable))
                    {
                        if (!description.Contains("Impossible to refine"))
                        {
                            description += "\r\nImpossible to refine this item.";
                        }
                    }

                    if (tupleSource.GetValue <bool>(ServerItemAttributes.Refineable))
                    {
                        if (description.Contains("Impossible to refine"))
                        {
                            description = description.Replace("Impossible to refine this item.", "").Trim('\r', '\n');
                        }
                    }
                }

                _autoAdd(ServerItemAttributes.Defense, ParameterHolderKeys.Defense, tupleSource, holder);
                _autoAddEquippedOn(ServerItemAttributes.Location, ParameterHolderKeys.Location, tupleSource, holder);
                _autoAddWeight(tupleSource, holder);
                _autoAddJob(tupleSource, holder, _getInt(equipLevelAttribute, tupleSource));
                break;

            case TypeType.Card:
                holder.Values[ParameterHolderKeys.Class] = "Card";
                _autoAddCompound(ServerItemAttributes.Location, ParameterHolderKeys.CompoundOn, tupleSource, holder);
                _autoAdd(equipLevelAttribute, ParameterHolderKeys.RequiredLevel, tupleSource, holder, 1);
                _autoAddWeight(tupleSource, holder);

                if (!item.GetValue <bool>(ClientItemAttributes.IsCard))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.IsCard, true));
                }

                if (String.IsNullOrEmpty(item.GetValue <string>(ClientItemAttributes.Illustration)))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.Illustration, "sorry"));
                }

                if (String.IsNullOrEmpty(item.GetValue <string>(ClientItemAttributes.Affix)))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.Affix, tupleSource.GetValue <string>(ServerItemAttributes.Name)));
                }

                const string CardResource = "À̸§¾ø´ÂÄ«µå";

                unDisplayName = tupleSource.GetValue <string>(ServerItemAttributes.Name);
                attribute     = ClientItemAttributes.UnidentifiedDisplayName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnDisplayName && _isNotNullDifferent(unDisplayName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unDisplayName));
                }

                unidentifiedResourceName = EncodingService.FromAnyToDisplayEncoding(CardResource);
                attribute = ClientItemAttributes.UnidentifiedResourceName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }

                attribute = ClientItemAttributes.IdentifiedResourceName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteIdResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }
                break;

            case TypeType.PetEgg:
                holder.Values[ParameterHolderKeys.Class] = "Monster Egg";
                _autoAddWeight(tupleSource, holder);
                break;

            case TypeType.PetEquip:
                holder.Values[ParameterHolderKeys.Class] = "Cute Pet Armor";
                _autoAddWeight(tupleSource, holder);

                int id = item.GetKey <int>();

                List <ReadableTuple <int> > tuples = pet1.Table.Tuples.Where(p => p.Value.GetValue <int>(ServerPetAttributes.EquipId) == id).Select(p => p.Value).Concat(
                    pet2.Table.Tuples.Where(p => p.Value.GetValue <int>(ServerPetAttributes.EquipId) == id).Select(p => p.Value)
                    ).ToList();

                if (tuples.Count > 0)
                {
                    // Try to retrieve the names
                    List <string> values = new List <string>();

                    foreach (ReadableTuple <int> tuple in tuples)
                    {
                        var pid = tuple.GetKey <int>();

                        var pTuple = mobDb2.Table.TryGetTuple(pid) ?? mobDb1.Table.TryGetTuple(pid);

                        if (pTuple != null)
                        {
                            values.Add(pTuple.GetValue <string>(ServerMobAttributes.KRoName));
                        }
                    }

                    if (values.Count > 0)
                    {
                        holder.Values[ParameterHolderKeys.ApplicablePet] = String.Join(", ", values.ToArray());
                    }
                }
                break;

            case TypeType.UsableItem:
                _autoAddPet(tupleSource, holder);
                _autoAddWeight(tupleSource, holder);
                _autoAddJobIfRestricted(tupleSource, holder);
                break;

            case TypeType.EtcItem:
            case TypeType.HealingItem:
            case TypeType.ShadowEquip:
            case TypeType.UsableWithDelayed:
            case TypeType.UsableWithDelayed2:
                _autoAddWeight(tupleSource, holder);
                _autoAddJobIfRestricted(tupleSource, holder);
                break;
            }

            _autoAdd(equipLevelAttribute, ParameterHolderKeys.RequiredLevel, tupleSource, holder, 1);

            holder.Values[ParameterHolderKeys.Description] = description == "" ? ProjectConfiguration.AutocompleteDescNotSet : description;

            var idDescription = holder.GenerateDescription();

            if (ProjectConfiguration.AutocompleteIdDescription)
            {
                if (idDescription != item.GetValue <string>(ClientItemAttributes.IdentifiedDescription))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.IdentifiedDescription, idDescription));
                }
            }

            var unDescription = item.GetValue <string>(ClientItemAttributes.UnidentifiedDescription);

            // unidentified
            switch (tupleSource.GetValue <TypeType>(ServerItemAttributes.Type))
            {
            case TypeType.Ammo:
            case TypeType.EtcItem:
            case TypeType.HealingItem:
            case TypeType.PetEgg:
            case TypeType.UsableItem:
            case TypeType.UsableWithDelayed:
            case TypeType.UsableWithDelayed2:
                if (ProjectConfiguration.AutocompleteUnDescription && unDescription != idDescription)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.UnidentifiedDescription, idDescription));
                }

                string unDisplayName = tupleSource.GetValue <string>(ServerItemAttributes.Name);
                attribute = ClientItemAttributes.UnidentifiedDisplayName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnDisplayName && _isNotNullDifferent(unDisplayName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unDisplayName));
                }

                string unidentifiedResourceName = item.GetValue <string>(ClientItemAttributes.IdentifiedResourceName);
                if (String.IsNullOrEmpty(unidentifiedResourceName))
                {
                    unidentifiedResourceName = EncodingService.FromAnyToDisplayEncoding("Á¶°¢ÄÉÀÌÅ©");                             // Cake
                }

                attribute = ClientItemAttributes.UnidentifiedResourceName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteUnResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }

                attribute = ClientItemAttributes.IdentifiedResourceName;
                if (_emptyFill(attribute, item) && ProjectConfiguration.AutocompleteIdResourceName && _isNotNullDifferent(unidentifiedResourceName, attribute, item))
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, attribute, unidentifiedResourceName));
                }
                break;

            case TypeType.Card:
                if (ProjectConfiguration.AutocompleteUnDescription && unDescription != idDescription)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.UnidentifiedDescription, idDescription));
                }
                break;

            default:
                if (ProjectConfiguration.AutocompleteUnDescription && unDescription != ProjectConfiguration.AutocompleteUnDescriptionFormat)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ClientItemAttributes.UnidentifiedDescription, ProjectConfiguration.AutocompleteUnDescriptionFormat));
                }
                break;
            }

            if (commands.Commands.Count == 0)
            {
                return(null);
            }

            return(commands);
        }
Esempio n. 2
0
        public static GroupCommand <TKey, ReadableTuple <TKey> > Generate <TKey>(ReadableTuple <TKey> item, bool execute)
        {
            GroupCommand <TKey, ReadableTuple <TKey> > commands = GroupCommand <TKey, ReadableTuple <TKey> > .Make();

            WebClient client = new WebClient();

            byte[] data;

            try {
                data = client.DownloadData("https://www.divine-pride.net/database/monster/" + item.Key);
            }
            catch {
                return(null);
            }

            string content = Encoding.Default.GetString(data);
            int    index   = content.IndexOf("Drop chance", 0, System.StringComparison.Ordinal);

            if (index < 0)
            {
                return(null);
            }

            HashSet <int> used = new HashSet <int>();

            var legentRestart = content.IndexOf("<legend>RE:Start</legend>", 0);

            while (true)
            {
                index = content.IndexOf("&nbsp;", index);

                if (index < -1)
                {
                    break;
                }

                if (legentRestart > -1 && index > legentRestart)
                {
                    break;
                }

                int start = index + "&nbsp;".Length;
                int end   = content.IndexOf("\r", start);
                index = end;

                string numberString = content.Substring(start, end - start);

                int nameid = 0;

                if (Int32.TryParse(numberString, out nameid))
                {
                    // find drop rate
                    int spanStart = content.IndexOf("<span>", end) + "<span>".Length;
                    int spanEnd   = content.IndexOf("%", spanStart);

                    string chanceString = content.Substring(spanStart, spanEnd - spanStart);

                    decimal value = (decimal)FormatConverters.SingleConverter(chanceString);

                    if (value > 0)
                    {
                        int  chance = (int)((decimal)value * 100);
                        bool found  = false;
                        int  free   = -1;

                        for (int i = ServerMobAttributes.Drop1ID.Index; i <= ServerMobAttributes.DropCardid.Index; i += 2)
                        {
                            if (used.Contains(i))
                            {
                                continue;
                            }

                            int nameidSource = item.GetValue <int>(i);
                            int chanceSource = item.GetValue <int>(i + 1);

                            if (nameidSource == 0 && free == -1)
                            {
                                free = i;
                            }

                            if (nameidSource != nameid)
                            {
                                continue;
                            }

                            found = true;
                            used.Add(i);

                            if (chanceSource == chance)
                            {
                                break;
                            }

                            commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.AttributeList.Attributes[i + 1], chance));
                            break;
                        }

                        if (!found)
                        {
                            commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.AttributeList.Attributes[free], nameid));
                            commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.AttributeList.Attributes[free + 1], chance));
                            used.Add(free);
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            {
                //string content = Encoding.Default.GetString(data);
                int start   = 0;
                int end     = 0;
                int atk1    = 0;
                int atk2    = 0;
                int matk1   = 0;
                int matk2   = 0;
                int level   = item.GetValue <int>(ServerMobAttributes.Lv);
                int strStat = item.GetValue <int>(ServerMobAttributes.Str);
                int intStat = item.GetValue <int>(ServerMobAttributes.Int);

                if (!MoveTo(content, "<td class=\"right\">", ref start, ref end))                 // mob id
                {
                    return(null);
                }

                MoveForward(ref start, ref end);

                try {
                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // mob level
                        level = ReadInteger(content, ref end);
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Lv, level));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // HP
                        //commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.Lv, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Attack
                        string span = ReadSpan(content, ref start, ref end);
                        span = span.Replace(",", "").Replace(" ", "");
                        string[] dataAtk = span.Split('-');
                        atk1 = Int32.Parse(dataAtk[0]);
                        atk2 = Int32.Parse(dataAtk[1]);
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Magic attack
                        string span = ReadSpan(content, ref start, ref end);
                        span = span.Replace(",", "").Replace(" ", "");
                        string[] dataAtk = span.Split('-');
                        matk1 = Int32.Parse(dataAtk[0]);
                        matk2 = Int32.Parse(dataAtk[1]);
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Speed
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Range
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Hit
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Flee
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Def
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Def, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Mdef
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Mdef, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Str
                        strStat = ReadInteger(content, ref end);
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Str, strStat));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Agi
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Agi, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Vit
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Vit, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Int
                        intStat = ReadInteger(content, ref end);
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Int, intStat));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Dex
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Dex, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                    {
                        // Luk
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Luk, ReadInteger(content, ref end)));
                    }

                    MoveForward(ref start, ref end);

                    atk1  = (atk2 + atk1) / 2 - strStat - level;
                    matk1 = (matk1 + matk2) / 2 - intStat - level;

                    int v1 = Math.Abs(item.GetValue <int>(ServerMobAttributes.Atk1) - atk1);
                    int v2 = Math.Abs((item.GetValue <int>(ServerMobAttributes.Atk2) - item.GetValue <int>(ServerMobAttributes.Atk1)) - matk1);

                    if (!execute)
                    {
                        if (v1 > 1 || v2 > 1)
                        {
                            Console.WriteLine("Invalid atk/matk for " + item.Key);
                        }

                        return(null);
                    }

                    if (level > 0)
                    {
                        // Look up experience
                        start = content.IndexOf("id=\"experience\"", System.StringComparison.Ordinal);
                        int tbStart = content.IndexOf("<tbody>", index);
                        int tbEnd   = content.IndexOf("</tbody>", tbStart);

                        while (end < tbEnd)
                        {
                            if (MoveTo(content, "<td class=\"right\">", ref start, ref end))
                            {
                                int lv = ReadInteger(content, ref end);
                                MoveForward(ref start, ref end);

                                if (lv == level)
                                {
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);

                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    int baseExp = ReadInteger(content, ref end);
                                    MoveForward(ref start, ref end);

                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    int jobExp = ReadInteger(content, ref end);
                                    MoveForward(ref start, ref end);

                                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Exp, baseExp));
                                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.JExp, jobExp));
                                    break;
                                }
                                else
                                {
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);
                                    MoveTo(content, "<td class=\"right\">", ref start, ref end);
                                    MoveForward(ref start, ref end);
                                }
                            }
                            else
                            {
                                MoveForward(ref start, ref end);
                            }
                        }
                    }

                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Atk1, atk1));
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Atk2, atk1 + matk1));
                }
                catch {
                    return(null);
                }
            }

            //while (true) {
            //	index = content.IndexOf("&nbsp;", index);
            //
            //	if (index < -1)
            //		break;
            //
            //	int start = index + "&nbsp;".Length;
            //	int end = content.IndexOf("\r", start);
            //	index = end;
            //
            //	string numberString = content.Substring(start, end - start);
            //
            //	int nameid = 0;
            //
            //	if (Int32.TryParse(numberString, out nameid)) {
            //		// find drop rate
            //		int spanStart = content.IndexOf("<span>", end) + "<span>".Length;
            //		int spanEnd = content.IndexOf("%", spanStart);
            //
            //		string chanceString = content.Substring(spanStart, spanEnd - spanStart);
            //
            //		decimal value = (decimal)FormatConverters.SingleConverter(chanceString);
            //
            //		if (value > 0) {
            //			int chance = (int)((decimal)value * 100);
            //			bool found = false;
            //			int free = -1;
            //
            //			for (int i = ServerMobAttributes.Drop1ID.Index; i <= ServerMobAttributes.DropCardid.Index; i += 2) {
            //				if (used.Contains(i))
            //					continue;
            //
            //				int nameidSource = item.GetValue<int>(i);
            //				int chanceSource = item.GetValue<int>(i + 1);
            //
            //				if (nameidSource == 0 && free == -1) {
            //					free = i;
            //				}
            //
            //				if (nameidSource != nameid)
            //					continue;
            //
            //				found = true;
            //				used.Add(i);
            //
            //				if (chanceSource == chance)
            //					break;
            //
            //				commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.AttributeList.Attributes[i + 1], chance));
            //				break;
            //			}
            //
            //			if (!found) {
            //				commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.AttributeList.Attributes[free], nameid));
            //				commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(item, ServerMobAttributes.AttributeList.Attributes[free + 1], chance));
            //			}
            //		}
            //	}
            //	else {
            //		break;
            //	}
            //}

            if (commands.Commands.Count == 0)
            {
                return(null);
            }

            return(commands);
        }
Esempio n. 3
0
        public static GroupCommand <TKey, ReadableTuple <TKey> > GeneratekRO <TKey>(ReadableTuple <TKey> item)
        {
            GroupCommand <TKey, ReadableTuple <TKey> > commands = GroupCommand <TKey, ReadableTuple <TKey> > .Make();

            WebClient client = new WebClient();

            byte[] data;

            try {
                string sprite = item.GetValue <string>(ServerMobAttributes.AegisName);

                if (String.IsNullOrEmpty(sprite))
                {
                    sprite = item.GetValue <string>(ServerMobAttributes.ClientSprite);
                }

                data = client.DownloadData("http://ro.gnjoy.com/guide/runemidgarts/popup/monsterview.asp?monsterID=" + sprite);
            }
            catch {
                return(null);
            }

            string content = EncodingService.Ansi.GetString(data);
            int    index   = content.IndexOf("몬스터 상세", 0, System.StringComparison.Ordinal);

            if (index < 0)
            {
                return(null);
            }

            string value;

            if ((value = _fetch(content, "공격력")) != null)
            {
                value = value.Replace(",", "").Replace(" ", "");
                string[] minmax = value.Split('~');

                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Atk1, minmax[0]));
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Atk2, minmax[1]));
            }

            if ((value = _fetch(content, "레벨")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Lv, Int32.Parse(value)));
            }

            if ((value = _fetch(content, "ë°©ì–´ë ¥")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Def, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "마법방어력")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Mdef, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "STR")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Str, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "DEX")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Dex, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "AGI")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Agi, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "VIT")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Vit, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "INT")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Int, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "LUK")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Luk, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "경험치")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.Exp, Int32.Parse(value.Replace(",", ""))));
            }

            if ((value = _fetch(content, "JOB 경험치")) != null)
            {
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(item, ServerMobAttributes.JExp, Int32.Parse(value.Replace(",", ""))));
            }

            if (commands.Commands.Count == 0)
            {
                return(null);
            }

            return(commands);
        }
        public static GroupCommand <TKey, ReadableTuple <TKey> > Generate <TKey>(ReadableTuple <TKey> clientTuple, ReadableTuple <int> serverTuple, bool autoComplete = false)
        {
            GroupCommand <TKey, ReadableTuple <TKey> > commands = GroupCommand <TKey, ReadableTuple <TKey> > .Make();

            if (autoComplete || ProjectConfiguration.AutocompleteRewardId)
            {
                int idC = clientTuple.GetValue <int>(ClientCheevoAttributes.RewardId);
                int idS = serverTuple.GetValue <int>(ServerCheevoAttributes.RewardId);

                if (idC != idS)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.RewardId, idS));
                }
            }

            if (autoComplete || ProjectConfiguration.AutocompleteTitleId)
            {
                int idC = clientTuple.GetValue <int>(ClientCheevoAttributes.RewardTitleId);
                int idS = serverTuple.GetValue <int>(ServerCheevoAttributes.RewardTitleId);

                if (idC != idS)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.RewardTitleId, idS));
                }
            }

            if (autoComplete || ProjectConfiguration.AutocompleteScore)
            {
                int idC = clientTuple.GetValue <int>(ClientCheevoAttributes.Score);
                int idS = serverTuple.GetValue <int>(ServerCheevoAttributes.Score);

                if (idC != idS)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Score, idS));
                }
            }

            if (autoComplete || ProjectConfiguration.AutocompleteName)
            {
                string idC = clientTuple.GetValue <string>(ClientCheevoAttributes.Name);
                string idS = serverTuple.GetValue <string>(ServerCheevoAttributes.Name);

                if (idC != idS)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Name, idS));
                }
            }

            if (autoComplete)
            {
                string idC = clientTuple.GetValue <string>(ClientCheevoAttributes.GroupId);
                string idS = serverTuple.GetValue <string>(ServerCheevoAttributes.GroupId);

                if (idC != idS)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.GroupId, idS.Replace("AG_", "")));
                }
            }

            if (autoComplete)
            {
                string name = serverTuple.GetValue <string>(ServerCheevoAttributes.Name);

                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Summary, name));
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Details, name));
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Major, "0"));
                commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Minor, "0"));

                int total = 0;

                for (int i = 0; i < 5; i++)
                {
                    total += serverTuple.GetValue <int>(ServerCheevoAttributes.TargetCount1.Index + 2 * i);
                }

                if (total > 0)
                {
                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.UiType, "1"));

                    CheevoResource resource = new CheevoResource("");

                    for (int i = 0; i < 5; i++)
                    {
                        int count    = serverTuple.GetValue <int>(ServerCheevoAttributes.TargetCount1.Index + 2 * i);
                        int targetId = serverTuple.GetValue <int>(ServerCheevoAttributes.TargetId1.Index + 2 * i);

                        if (count > 0)
                        {
                            string text = "Task " + (i + 1);

                            if (targetId > 0)
                            {
                                var table = SdeEditor.Instance.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs);
                                var tuple = table.TryGetTuple(targetId);

                                if (tuple != null)
                                {
                                    string mobName = tuple.GetValue <string>(ServerMobAttributes.IRoName);

                                    text = "Defeat " + mobName + " " + (count == 1 ? "once!" : count + " times!");
                                }
                            }

                            resource.Items.Add(new CheevoResourceItem {
                                Id    = i + 1,
                                Count = count,
                                Text  = text
                            });
                        }
                    }

                    commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Resources, resource.GetData()));
                }
            }

            if (autoComplete)
            {
            }
            else if (ProjectConfiguration.AutocompleteCount)
            {
                int    uiType = clientTuple.GetValue <int>(ClientCheevoAttributes.UiType);
                string group  = serverTuple.GetValue <string>(ServerCheevoAttributes.GroupId);

                if (uiType == 1 && group != "AG_SPEND_ZENY")
                {
                    string         oldData  = clientTuple.GetValue <string>(ClientCheevoAttributes.Resources);
                    CheevoResource resource = new CheevoResource(oldData);

                    for (int i = 0; i < 5; i++)
                    {
                        int targetCount = serverTuple.GetValue <int>(ServerCheevoAttributes.TargetCount1.Index + 2 * i);

                        if (i < resource.Items.Count && targetCount != resource.Items[i].Count)
                        {
                            if (resource.Items[i].Text.Contains(resource.Items[i].Count.ToString(CultureInfo.InvariantCulture)))
                            {
                                resource.Items[i].Text = resource.Items[i].Text.Replace(resource.Items[i].Count.ToString(CultureInfo.InvariantCulture), targetCount.ToString(CultureInfo.InvariantCulture));
                            }

                            resource.Items[i].Count = targetCount;
                        }
                    }

                    if (oldData != resource.ToString())
                    {
                        commands.Add(new ChangeTupleProperty <TKey, ReadableTuple <TKey> >(clientTuple, ClientCheevoAttributes.Resources, resource.GetData()));
                    }
                }
            }

            //if (ProjectConfiguration.AutocompleteBuff) {
            //	int rewardIdC = clientTuple.GetValue<int>(ClientCheevoAttributes.RewardId);
            //	int rewardIdS = serverTuple.GetValue<int>(ServerCheevoAttributes.RewardId);
            //
            //	if (rewardIdC != rewardIdS) {
            //		commands.Add(new ChangeTupleProperty<TKey, ReadableTuple<TKey>>(clientTuple, ClientItemAttributes.NumberOfSlots, rewardIdS));
            //	}
            //}

            if (commands.Commands.Count == 0)
            {
                return(null);
            }

            return(commands);
        }