예제 #1
0
        public void ProcessGeneratorQueue()
        {
            var index = 0;

            while (index < GeneratorQueue.Count)
            {
                double ts = Common.Time.GetTimestamp();
                if (ts >= GeneratorQueue[index].When)
                {
                    if (GeneratorRegistry.Count >= MaxGeneratedObjects)
                    {
                        // System.Diagnostics.Debug.WriteLine($"GeneratorRegistry for {Guid.Full} is at MaxGeneratedObjects {MaxGeneratedObjects}");
                        // System.Diagnostics.Debug.WriteLine($"Removing {GeneratorQueue[index].Slot} from GeneratorQueue for {Guid.Full}");
                        GeneratorQueue.RemoveAt(index);
                        index++;
                        continue;
                    }
                    var profile = GeneratorProfiles[(int)GeneratorQueue[index].Slot];

                    var rNode = new GeneratorRegistryNode();

                    rNode.WeenieClassId = profile.WeenieClassId;
                    rNode.Timestamp     = Common.Time.GetTimestamp();
                    rNode.Slot          = GeneratorQueue[index].Slot;

                    var wo = WorldObjectFactory.CreateNewWorldObject(profile.WeenieClassId);

                    if (wo != null)
                    {
                        switch ((RegenLocationType)profile.WhereCreate)
                        {
                        case RegenLocationType.SpecificTreasure:
                        case RegenLocationType.Specific:
                            if ((profile.ObjCellId ?? 0) > 0)
                            {
                                wo.Location = new ACE.Entity.Position(profile.ObjCellId ?? 0,
                                                                      profile.OriginX ?? 0, profile.OriginY ?? 0, profile.OriginZ ?? 0,
                                                                      profile.AnglesX ?? 0, profile.AnglesY ?? 0, profile.AnglesZ ?? 0, profile.AnglesW ?? 0);
                            }
                            else
                            {
                                wo.Location = new ACE.Entity.Position(Location.Cell,
                                                                      Location.PositionX + profile.OriginX ?? 0, Location.PositionY + profile.OriginY ?? 0, Location.PositionZ + profile.OriginZ ?? 0,
                                                                      profile.AnglesX ?? 0, profile.AnglesY ?? 0, profile.AnglesZ ?? 0, profile.AnglesW ?? 0);
                            }
                            break;

                        case RegenLocationType.ScatterTreasure:
                        case RegenLocationType.Scatter:
                            float genRadius = (float)(GetProperty(PropertyFloat.GeneratorRadius) ?? 0f);
                            var   random_x  = Physics.Common.Random.RollDice(genRadius * -1, genRadius);
                            var   random_y  = Physics.Common.Random.RollDice(genRadius * -1, genRadius);
                            var   pos       = new Physics.Common.Position(Location);
                            wo.Location = new ACE.Entity.Position(pos.ObjCellID, pos.Frame.Origin.X, pos.Frame.Origin.Y, pos.Frame.Origin.Z, pos.Frame.Orientation.X, pos.Frame.Orientation.Y, pos.Frame.Orientation.Z, pos.Frame.Orientation.W);
                            var newPos = wo.Location.Pos + new Vector3(random_x, random_y, 0.0f);
                            if (!Location.Indoors)
                            {
                                // Based on GDL scatter
                                newPos.X = Math.Clamp(newPos.X, 0.5f, 191.5f);
                                newPos.Y = Math.Clamp(newPos.Y, 0.5f, 191.5f);
                                wo.Location.SetPosition(newPos);
                                newPos.Z = LScape.get_landblock(wo.Location.Cell).GetZ(newPos);
                            }
                            wo.Location.SetPosition(newPos);
                            break;

                        default:
                            wo.Location = Location;
                            break;
                        }

                        wo.Generator   = this;
                        wo.GeneratorId = Guid.Full;

                        // System.Diagnostics.Debug.WriteLine($"Adding {wo.Guid.Full} | {rNode.Slot} in GeneratorRegistry for {Guid.Full}");
                        GeneratorRegistry.Add(wo.Guid.Full, rNode);
                        GeneratorCache.Add(wo.Guid.Full, wo);
                        // System.Diagnostics.Debug.WriteLine($"Spawning {GeneratorQueue[index].Slot} in GeneratorQueue for {Guid.Full}");
                        wo.EnterWorld();
                        // System.Diagnostics.Debug.WriteLine($"Removing {GeneratorQueue[index].Slot} from GeneratorQueue for {Guid.Full}");
                        GeneratorQueue.RemoveAt(index);
                    }
                    else
                    {
                        // System.Diagnostics.Debug.WriteLine($"Removing {GeneratorQueue[index].Slot} from GeneratorQueue for {Guid.Full} because wcid {rNode.WeenieClassId} is not in the database");
                        GeneratorQueue.RemoveAt(index);
                    }
                }
                else
                {
                    index++;
                }
            }
        }
예제 #2
0
        public void ProcessGeneratorQueue()
        {
            var index = 0;

            while (index < GeneratorQueue.Count)
            {
                double ts = Common.Time.GetTimestamp();
                if (ts >= GeneratorQueue[index].When)
                {
                    if (GeneratorRegistry.Count >= MaxGeneratedObjects)
                    {
                        // System.Diagnostics.Debug.WriteLine($"GeneratorRegistry for {Guid.Full} is at MaxGeneratedObjects {MaxGeneratedObjects}");
                        // System.Diagnostics.Debug.WriteLine($"Removing {GeneratorQueue[index].Slot} from GeneratorQueue for {Guid.Full}");
                        GeneratorQueue.RemoveAt(index);
                        index++;
                        continue;
                    }
                    var profile = GeneratorProfiles[(int)GeneratorQueue[index].Slot];

                    var rNode = new GeneratorRegistryNode();

                    rNode.WeenieClassId = profile.WeenieClassId;
                    rNode.Timestamp     = Common.Time.GetTimestamp();
                    rNode.Slot          = GeneratorQueue[index].Slot;

                    var wo = WorldObjectFactory.CreateNewWorldObject(profile.WeenieClassId);

                    if (wo != null)
                    {
                        switch (profile.WhereCreate)
                        {
                        case 4:
                            wo.Location = new Position(profile.ObjCellId ?? 0,
                                                       profile.OriginX ?? 0, profile.OriginY ?? 0, profile.OriginZ ?? 0,
                                                       profile.AnglesX ?? 0, profile.AnglesY ?? 0, profile.AnglesZ ?? 0, profile.AnglesW ?? 0);
                            break;

                        default:
                            wo.Location = Location;
                            break;
                        }

                        wo.GeneratorId = Guid.Full;

                        // System.Diagnostics.Debug.WriteLine($"Adding {wo.Guid.Full} | {rNode.Slot} in GeneratorRegistry for {Guid.Full}");
                        GeneratorRegistry.Add(wo.Guid.Full, rNode);
                        // System.Diagnostics.Debug.WriteLine($"Spawning {GeneratorQueue[index].Slot} in GeneratorQueue for {Guid.Full}");
                        wo.EnterWorld();
                        // System.Diagnostics.Debug.WriteLine($"Removing {GeneratorQueue[index].Slot} from GeneratorQueue for {Guid.Full}");
                        GeneratorQueue.RemoveAt(index);
                    }
                    else
                    {
                        // System.Diagnostics.Debug.WriteLine($"Removing {GeneratorQueue[index].Slot} from GeneratorQueue for {Guid.Full} because wcid {rNode.WeenieClassId} is not in the database");
                        GeneratorQueue.RemoveAt(index);
                    }
                }
                else
                {
                    index++;
                }
            }
        }