public static ICharacter InstantiateMobSpawn(
            DBMobSpawn mob,
            DBMobSpawnStat[] stats,
            IController npccontroller,
            IPlayfield playfield)
        {
            if (playfield != null)
            {
                Identity mobId = new Identity()
                {
                    Type = IdentityType.CanbeAffected, Instance = mob.Id
                };
                if (Pool.Instance.GetObject(playfield.Identity, mobId) != null)
                {
                    throw new Exception("Object " + mobId.ToString() + " already exists!!");
                }
                Character cmob = new Character(playfield.Identity, mobId, npccontroller);
                cmob.Read();
                cmob.Playfield = playfield;
                cmob.Coordinates(new Coordinate()
                {
                    x = mob.X, y = mob.Y, z = mob.Z
                });
                cmob.RawHeading = new Quaternion(mob.HeadingX, mob.HeadingY, mob.HeadingZ, mob.HeadingW);
                cmob.Name       = mob.Name;
                cmob.FirstName  = "";
                cmob.LastName   = "";
                foreach (DBMobSpawnStat stat in stats)
                {
                    cmob.Stats.SetBaseValueWithoutTriggering(stat.Stat, (uint)stat.Value);
                }

                cmob.Stats.SetBaseValueWithoutTriggering((int)StatIds.visualprofession, cmob.Stats[StatIds.profession].BaseValue);
                // initiate affected stats calculation
                int temp = cmob.Stats[StatIds.level].Value;
                temp = cmob.Stats[StatIds.agility].Value;
                temp = cmob.Stats[StatIds.headmesh].Value;
                cmob.MeshLayer.AddMesh(0, cmob.Stats[StatIds.headmesh].Value, 0, 4);
                cmob.SocialMeshLayer.AddMesh(0, cmob.Stats[StatIds.headmesh].Value, 0, 4);
                List <MobSpawnWaypoint> waypoints =
                    MessagePackZip.DeserializeData <MobSpawnWaypoint>(mob.Waypoints.ToArray());
                foreach (MobSpawnWaypoint wp in waypoints)
                {
                    Waypoint mobwp = new Waypoint();
                    mobwp.Position.x = wp.X;
                    mobwp.Position.y = wp.Y;
                    mobwp.Position.z = wp.Z;
                    mobwp.Running    = wp.WalkMode == 1;
                    cmob.Waypoints.Add(mobwp);
                }
                npccontroller.Character = cmob;
                if (cmob.Waypoints.Count > 2)
                {
                    cmob.Controller.State = CharacterState.Patrolling;
                }
                cmob.DoNotDoTimers = false;
                return(cmob);
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// </summary>
        /// <param name="fname">
        /// </param>
        /// <returns>
        /// </returns>
        public static int CacheAllPlayfieldData(string fname)
        {
            PFData = new Dictionary <int, PlayfieldData>();

            MessagePackZip.UncompressData <PlayfieldData>(fname).ForEach(x => PFData.Add(x.PlayfieldId, x));

            Console.WriteLine("Tweaking in some Statel functions");

            // Now lets do some tweaking

            foreach (PlayfieldData pfd in PFData.Values)
            {
                foreach (StatelData sd in pfd.Statels)
                {
                    if (ItemLoader.ItemList.ContainsKey(sd.TemplateId))
                    {
                        if (ItemLoader.ItemList[sd.TemplateId].WantsCollision() &&
                            (!sd.Events.Any(x => x.EventType == (int)EventType.OnCollide)) &&
                            sd.Events.Any(x => x.EventType == (int)EventType.OnUse))
                        {
                            Events ev = sd.Events.First(x => x.EventType == (int)EventType.OnUse).Copy();
                            ev.EventType = (int)EventType.OnCollide;
                            sd.Events.Add(ev);
                        }
                    }
                }
            }

            GC.Collect();
            return(PFData.Count);
        }
コード例 #3
0
        /// <summary>
        /// Cache all item templates
        /// </summary>
        /// <param name="fname">
        /// File to load from
        /// </param>
        /// <returns>
        /// Number of cached items
        /// </returns>
        public static int CacheAllItems(string fname)
        {
            Contract.Requires(!string.IsNullOrEmpty(fname));
            DateTime _now = DateTime.UtcNow;

            MessagePackZip.UncompressData <ItemTemplate>(fname).ForEach(x => ItemList.Add(x.ID, x));

            Console.WriteLine(
                locales.ItemLoaderLoadedItems + " - {1}\r",
                new object[] { ItemList.Count, new DateTime((DateTime.UtcNow - _now).Ticks).ToString("mm:ss.ff") });

            GC.Collect();
            return(ItemList.Count);
        }
コード例 #4
0
        private void LoadStaticDynels(Identity playfieldIdentity)
        {
            IEnumerable <DBStaticDynel> dynels =
                StaticDynelDao.Instance.GetWhere(new { Playfield = playfieldIdentity.Instance });

            foreach (DBStaticDynel sd in dynels)
            {
                List <GameTuple <CharacterStat, uint> > tempStats =
                    MessagePackZip.DeserializeData <GameTuple <CharacterStat, uint> >(sd.stats.ToArray());

                if (tempStats.Any(x => x.Value1 == (CharacterStat)StatIds.acgitemtemplateid))
                {
                    int         id  = (int)tempStats.First(x => x.Value1 == (CharacterStat)StatIds.acgitemtemplateid).Value2;
                    StaticDynel sdy = new StaticDynel(
                        this.Identity,
                        new Identity()
                    {
                        Type = (IdentityType)sd.Type, Instance = sd.Instance
                    },
                        ItemLoader.ItemList[id]);

                    foreach (GameTuple <CharacterStat, uint> stat in tempStats)
                    {
                        if (sdy.Stats.ContainsKey((int)stat.Value1))
                        {
                            sdy.Stats[(int)stat.Value1] = (int)stat.Value2;
                            continue;
                        }
                        sdy.Stats.Add((int)stat.Value1, (int)stat.Value2);
                    }

                    sdy.Coordinate = new Coordinate(sd.X, sd.Y, sd.Z);
                    sdy.Heading    = new Quaternion()
                    {
                        X = sd.HeadingX,
                        Y = sd.HeadingY,
                        Z = sd.HeadingZ,
                        W = sd.HeadingW
                    };
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// </summary>
        /// <param name="fname">
        /// </param>
        /// <returns>
        /// </returns>
        public static int CacheAllPlayfieldData(string fname)
        {
            PFData = new Dictionary <int, PlayfieldData>();

            MessagePackZip.UncompressData <PlayfieldData>(fname).ForEach(x => PFData.Add(x.PlayfieldId, x));

            Console.WriteLine("Tweaking in some Statel functions");

            // Now lets do some tweaking

            foreach (PlayfieldData pfd in PFData.Values)
            {
                foreach (StatelData sd in pfd.Statels)
                {
                    bool foundproxyteleport = false;
                    int  playfieldid        = 0;
                    int  doorinstance       = 0;
                    foreach (Event ev in sd.Events)
                    {
                        foreach (Function f in ev.Functions)
                        {
                            if (f.FunctionType == (int)FunctionType.TeleportProxy)
                            {
                                foundproxyteleport = true;
                                playfieldid        = f.Arguments.Values[1].AsInt32();
                                doorinstance       =
                                    (int)
                                    ((uint)0xC0000000 | f.Arguments.Values[1].AsInt32()
                                     | (f.Arguments.Values[2].AsInt32() << 16));
                                DBTeleport teleporter =
                                    TeleportDao.Instance.GetWhere(new { statelInstance = (uint)sd.Identity.Instance })
                                    .FirstOrDefault();
                                if (teleporter != null)
                                {
                                    doorinstance          = (int)teleporter.destinationInstance;
                                    f.Arguments.Values[2] = new MessagePackObject(((doorinstance >> 16) & 0xff));
                                }
                                break;
                            }
                            if (f.FunctionType == (int)FunctionType.TeleportProxy2)
                            {
                                playfieldid  = f.Arguments.Values[1].AsInt32();
                                doorinstance =
                                    (int)
                                    ((uint)0xC0000000 | f.Arguments.Values[1].AsInt32()
                                     | (f.Arguments.Values[2].AsInt32() << 16));
                                DBTeleport teleporter =
                                    TeleportDao.Instance.GetWhere(new { statelInstance = (uint)sd.Identity.Instance })
                                    .FirstOrDefault();
                                if (teleporter != null)
                                {
                                    doorinstance          = (int)teleporter.destinationInstance;
                                    f.Arguments.Values[2] = new MessagePackObject(((doorinstance >> 16) & 0xff));
                                }
                            }
                        }
                        if (foundproxyteleport)
                        {
                            break;
                        }
                    }

                    if (ItemLoader.ItemList.ContainsKey(sd.TemplateId))
                    {
                        if (ItemLoader.ItemList[sd.TemplateId].WantsCollision() &&
                            !ItemLoader.ItemList[sd.TemplateId].StatelCollisionDisabled() &&
                            (sd.Events.All(x => x.EventType != EventType.OnCollide)) &&
                            sd.Events.Any(x => x.EventType == EventType.OnUse))
                        {
                            Event ev = sd.Events.First(x => x.EventType == EventType.OnUse).Copy();
                            ev.EventType = EventType.OnCollide;
                            sd.Events.Add(ev);
                        }
                    }

                    if (foundproxyteleport)
                    {
                        if (PFData.ContainsKey(playfieldid))
                        {
                            StatelData internalDoor = PFData[playfieldid].GetDoor(doorinstance);
                            if (internalDoor != null)
                            {
                                if (internalDoor.Events.All(x => x.EventType != EventType.OnEnter))
                                {
                                    Event ev = new Event();
                                    ev.EventType = EventType.OnEnter;
                                    ev.Functions.Add(
                                        new Function()
                                    {
                                        FunctionType = (int)FunctionType.ExitProxyPlayfield
                                    });
                                    internalDoor.Events.Add(ev);
                                }
                            }
                        }
                    }
                }
            }

            return(PFData.Count);
        }
コード例 #6
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            OnScreenBanner.PrintCellAOBanner(ConsoleColor.White);

            Console.WriteLine();

            string AOPath = GetAOPath();

            if (AOPath == string.Empty)
            {
                // Exit
                return;
            }

            Console.WriteLine();
            Console.WriteLine("Loading item relations...");
            ReadItemRelations();

            PrepareItemNamesSQL();

            Console.WriteLine("Number of Items to extract: " + extractor.GetRecordInstances(Extractor.RecordType.Item).Length);

            // ITEM RECORD TYPE
            Console.WriteLine("Number of Nanos to extract: " + extractor.GetRecordInstances(Extractor.RecordType.Nano).Length);
            Console.WriteLine();

            // NANO RECORD TYPE

            // Console.WriteLine(extractor.GetRecordInstances(0xF4241).Length); // Playfields
            // Console.WriteLine(extractor.GetRecordInstances(0xF4266).Length); // Nano Strains
            // Console.WriteLine(extractor.GetRecordInstances(0xF4264).Length); // Perks

            // GetData(@"D:\c#\extractor serializer\data\items\",0xf4254);
            // GetData(@"D:\c#\extractor serializer\data\nanos\",0xfde85);
            // GetData(@"D:\c#\extractor serializer\data\playfields\",0xf4241);
            // GetData(@"D:\c#\extractor serializer\data\nanostrains\",0xf4266);
            // GetData(@"D:\c#\extractor serializer\data\perks\",0xf4264);

            Console.WriteLine();
            List <NanoFormula> rawNanoList = ReadNanoFormulas();

            Console.WriteLine();
            Console.WriteLine("Nanos extracted: " + rawNanoList.Count);
            Console.WriteLine();

            List <string>       ItemNamesSql = new List <string>(extractor.GetRecordInstanceCount(0xF4254));
            List <ItemTemplate> rawItemList  = ExtractItemTemplates(ItemNamesSql);

            Console.WriteLine("Items extracted: " + rawItemList.Count);

            SetItemRelations(rawItemList);

            CompactingItemNamesSql(ItemNamesSql);

            // SerializationContext.Default.Serializers.Register(new AOFunctionArgumentsSerializer());
            Console.WriteLine();
            Console.WriteLine("Items extracted: " + rawItemList.Count);

            Console.WriteLine();
            Console.WriteLine("Creating serialized nano data file - please wait");

            string version = GetVersion(AOPath);

            MessagePackZip.CompressData <NanoFormula>("nanos.dat", version, rawNanoList, (rawNanoList.Count / 12) + 1);

            Console.WriteLine();
            Console.WriteLine("Checking Nanos...");
            Console.WriteLine();
            NanoLoader.CacheAllNanos("nanos.dat");
            Console.WriteLine();
            Console.WriteLine("Nanos: " + NanoLoader.NanoList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Creating serialized item data file - please wait");

            MessagePackZip.CompressData <ItemTemplate>("items.dat", GetVersion(AOPath), rawItemList, 10000);

            Console.WriteLine();
            Console.WriteLine("Checking Items...");
            Console.WriteLine();

            ItemLoader.CacheAllItems("items.dat");

            Console.WriteLine();
            Console.WriteLine("Items: " + ItemLoader.ItemList.Count + " successfully converted");

            Console.WriteLine("Extracting playfield walls/destinations/statels");
            List <PlayfieldData> playfields = ExtractPlayfieldData();

            ExtractPlayfieldStatels(playfields);
            Console.WriteLine();
            Console.WriteLine("Compressing playfield data...");
            MessagePackZip.CompressData <PlayfieldData>("playfields.dat", GetVersion(AOPath), playfields);
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("Further Instructions:");
            Console.WriteLine(
                "- Copy items.dat, nanos.dat and playfields.dat into your CellAO/Datafiles folder and overwrite.");
            Console.WriteLine("- Apply itemnames.sql to your database");
            Console.WriteLine();
            Console.WriteLine("   OR   ");
            Console.WriteLine();
            Console.WriteLine("Let me copy it over to the Source Tree");
            Console.WriteLine();
            while (true)
            {
                Console.WriteLine("Please choose:");
                Console.WriteLine("1: Copy the files to CellAO/Datafiles and CellAO/.../CellAO.Database/SqlTables.");
                Console.WriteLine("2: Exit and copy yourself");
                Console.WriteLine("[1,2]:");
                string line = Console.ReadLine();
                if (line.Trim() == "1")
                {
                    if (CopyDatafiles())
                    {
                        break;
                    }
                }

                if (line.Trim() == "2")
                {
                    break;
                }
            }

            while (true)
            {
                Console.WriteLine("Do you want to extract the icons for WebCore? [Y/N]");
                string line = Console.ReadLine();
                if (line.Trim().ToLower() == "y")
                {
                    ExtractIcons();
                    break;
                }
                if (line.Trim().ToLower() == "n")
                {
                    break;
                }
            }

            Console.WriteLine("Press a key to exit.");
            Console.ReadLine();
        }
コード例 #7
0
ファイル: Npc.cs プロジェクト: wowpin/CellAO-NightPredator
        public override void ExecuteCommand(ICharacter character, Identity target, string[] args)
        {
            if (args[1].ToLower() == "save")
            {
                Character mob = Pool.Instance.GetObject <Character>(character.Playfield.Identity, target);
                if (mob == null)
                {
                    character.Playfield.Publish(ChatTextMessageHandler.Default.CreateIM(character, "Not a NPC?"));
                    return;
                }

                if (!(mob.Controller is NPCController))
                {
                    character.Playfield.Publish(
                        ChatTextMessageHandler.Default.CreateIM(
                            character,
                            "Don't try to remove/save other players please."));
                }

                DBMobSpawn mobdbo = new DBMobSpawn();
                mobdbo.Id        = mob.Identity.Instance;
                mobdbo.Name      = mob.Name;
                mobdbo.Textures0 = 0;
                mobdbo.Textures1 = 0;
                mobdbo.Textures2 = 0;
                mobdbo.Textures3 = 0;
                mobdbo.Textures4 = 0;
                mobdbo.Playfield = mob.Playfield.Identity.Instance;
                Coordinate tempCoordinate = mob.Coordinates();
                mobdbo.X        = tempCoordinate.x;
                mobdbo.Y        = tempCoordinate.y;
                mobdbo.Z        = tempCoordinate.z;
                mobdbo.HeadingW = mob.Heading.wf;
                mobdbo.HeadingX = mob.Heading.xf;
                mobdbo.HeadingY = mob.Heading.yf;
                mobdbo.HeadingZ = mob.Heading.zf;
                if (mob.Waypoints.Count > 0)
                {
                    List <MobSpawnWaypoint> temp = this.GetMobWaypoints(mob);
                    mobdbo.Waypoints = new Binary(MessagePackZip.SerializeData(temp));
                }

                if (MobSpawnDao.Instance.Exists(mobdbo.Id))
                {
                    MobSpawnDao.Instance.Delete(mobdbo.Id);
                }

                MobSpawnDao.Instance.Add(mobdbo);

                // Clear remnants first
                MobSpawnStatDao.Instance.Delete(new { mobdbo.Id, mobdbo.Playfield });
                Dictionary <int, uint> statsToSave = mob.Stats.GetStatValues();
                foreach (KeyValuePair <int, uint> kv in statsToSave)
                {
                    MobSpawnStatDao.Instance.Add(
                        new DBMobSpawnStat()
                    {
                        Id        = mob.Identity.Instance,
                        Playfield = mob.Playfield.Identity.Instance,
                        Stat      = kv.Key,
                        Value     = (int)kv.Value
                    });
                }
            }
            if (args[1].ToLower() == "remove")
            {
                MobSpawnDao.Instance.Delete(target.Instance);
            }

            if (args[1].ToLower() == "knubot")
            {
                ICharacter cmob = Pool.Instance.GetObject <ICharacter>(character.Playfield.Identity, target);
                if (cmob == null)
                {
                    character.Playfield.Publish(
                        ChatTextMessageHandler.Default.CreateIM(
                            character,
                            string.Format("Target {0} is no npc.", target.ToString(true))));
                    return;
                }

                string scriptname = args[2];
                scriptname = ScriptCompiler.Instance.ClassExists(scriptname);
                if (scriptname != "")
                {
                    DBMobSpawn mob = MobSpawnDao.Instance.Get(target.Instance);
                    if (mob == null)
                    {
                        character.Playfield.Publish(
                            ChatTextMessageHandler.Default.CreateIM(
                                character,
                                string.Format(
                                    "Target npc {0} is not yet saved to mobspawn table.",
                                    target.ToString(true))));
                    }
                    else
                    {
                        mob.KnuBotScriptName = scriptname;
                        MobSpawnDao.Instance.Save(mob);
                        character.Playfield.Publish(
                            ChatTextMessageHandler.Default.CreateIM(
                                character,
                                string.Format(
                                    "Saved initialization script '{0}' for spawn {1}.",
                                    args[2],
                                    target.ToString(true))));
                        ((NPCController)cmob.Controller).SetKnuBot(
                            ScriptCompiler.Instance.CreateKnuBot(scriptname, cmob.Identity));
                    }
                }
                else
                {
                    character.Playfield.Publish(
                        ChatTextMessageHandler.Default.CreateIM(
                            character,
                            string.Format("Script '{0}' does not exist.", args[2])));
                }
            }
        }