Exemplo n.º 1
0
        public static void SynchronizeElements()
        {
            foreach (var skill in SkillRecord.Skills)
            {
                if (skill.GfxLookId != -1)
                {
                    List <InteractiveElementRecord> elements = InteractiveElementRecord.GetElementByGfxLookId(skill.GfxLookId);

                    foreach (var element in elements)
                    {
                        if (element.ElementType == -1)
                        {
                            element.ElementType = skill.InteractiveId;


                            if (!InteractiveSkillRecord.OneExist(element.ElementId))
                            {
                                int uid = InteractiveSkillRecord.InteractiveSkills.DynamicPop(w => w.UID);
                                InteractiveSkillRecord record = new InteractiveSkillRecord(uid, "Collect", string.Empty, string.Empty, element.ElementId, skill.Id);
                                record.AddInstantElement();
                            }

                            element.UpdateInstantElement();
                            logger.Gray("Element fixed: " + element.ElementId + " with skill " + skill.Name);
                        }
                    }
                }
            }
        }
        private static void AddAllInteractivesOfGfx(WorldClient client, string[] args)
        {
            if (args.Length < 4)
            {
                if (args.Length != 1)
                {
                    client.Character.ReplyError("Invalid command.");
                }

                client.Character.Reply("Add an all interactive elements of specific GfxLookId.");
                client.Character.Reply("» .elements addall|aa $GfxLookId $ElementType $SkillId");
                client.Character.Reply("» Example: .elements addall 685 108 154  ");
                client.Character.Reply(" - <b>$GfxLookId</b> ⇒ The element GxfLookId (see <i>.elements show</i>)");
                client.Character.Reply(" - <b>$ElementType</b> ⇒ ElementType (id in interactives table) of the resource.");
                client.Character.Reply(" - <b>$SkillId</b> ⇒ The ID of the skill.");

                return;
            }

            int    gfxLookId   = int.Parse(args[1]);
            int    elementType = int.Parse(args[2]);
            ushort skillId     = ushort.Parse(args[3]);

            const string actionType = "Collect";

            int nextUid = InteractiveSkillRecord.InteractiveSkills.DynamicPop(x => x.UID);

            client.Character.Reply($"Retrieving element records with GfxLookId={gfxLookId}...");
            List <InteractiveElementRecord> elementRecords = InteractiveElementRecord.GetElementByGfxLookId(gfxLookId);

            int           counter        = 1;
            int           total          = elementRecords.Count;
            HashSet <int> impactedMapIds = new HashSet <int>();

            client.Character.Reply($"Updating {elementRecords.Count} element records...");
            foreach (InteractiveElementRecord record in elementRecords)
            {
                // Update InteractiveElement
                if (record.ElementType != elementType)
                {
                    record.ElementType = elementType;
                    record.UpdateInstantElement();
                }

                client.Character.Reply($"Updated {counter}/{total} InteractiveElement.");

                // Insert InteractiveSkill if not exists
                if (!InteractiveSkillRecord.InteractiveSkills.Exists(isk => isk.ElementId == record.ElementId && isk.SkillId == skillId && isk.ActionType.Equals(actionType)))
                {
                    InteractiveSkillRecord newRecord = new InteractiveSkillRecord(nextUid, actionType, "", "", record.ElementId, skillId);
                    // InteractiveSkillRecord.InteractiveSkills.Add(newRecord);
                    newRecord.AddInstantElement();
                    nextUid++;

                    client.Character.Reply($"Created {counter}/{total} InteractiveSKill.");
                }
                else
                {
                    client.Character.Reply($"InteractiveSKill {counter}/{total} Already exists.");
                }

                impactedMapIds.Add(record.MapId);
                counter++;
            }

            client.Character.Reply("Database updated.");

            counter = 1;
            total   = impactedMapIds.Count;
            client.Character.Reply($"Reloading {impactedMapIds.Count} maps...");
            foreach (int mapId in impactedMapIds)
            {
                MapRecord.GetMap(mapId).Instance.Reload();
                client.Character.Reply($"Map {counter}/{total} reloaded: {mapId}");
                counter++;
            }

            client.Character.Reply("All maps have been reloaded.");

            client.Character.Reply("Done!");
        }