Ejemplo n.º 1
0
        private static void HandleTriggerAndPlaceableQuestLogic(NWPlayer oPC, NWObject oObject)
        {
            if (!oPC.IsPlayer)
            {
                return;
            }
            string questMessage       = oObject.GetLocalString("QUEST_MESSAGE");
            int    questID            = oObject.GetLocalInt("QUEST_ID");
            int    questSequence      = oObject.GetLocalInt("QUEST_SEQUENCE");
            string visibilityObjectID = oObject.GetLocalString("VISIBILITY_OBJECT_ID");

            if (questID <= 0)
            {
                oPC.SendMessage("QUEST_ID variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            if (questSequence <= 0)
            {
                oPC.SendMessage("QUEST_SEQUENCE variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            PCQuestStatus pcQuestStatus = DataService.SingleOrDefault <PCQuestStatus>(x => x.PlayerID == oPC.GlobalID && x.QuestID == questID);

            if (pcQuestStatus == null)
            {
                return;
            }

            QuestState questState = DataService.Get <QuestState>(pcQuestStatus.CurrentQuestStateID);

            if (questState.Sequence != questSequence ||
                (questState.QuestTypeID != (int)QuestType.UseObject &&
                 questState.QuestTypeID != (int)QuestType.ExploreArea))
            {
                return;
            }


            if (!string.IsNullOrWhiteSpace(questMessage))
            {
                _.DelayCommand(1.0f, () =>
                {
                    oPC.SendMessage(questMessage);
                });
            }

            AdvanceQuestState(oPC, oObject, questID);

            if (!string.IsNullOrWhiteSpace(visibilityObjectID))
            {
                ObjectVisibilityService.AdjustVisibility(oPC, oObject, false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Progresses a player to the next state if they meet all requirements to do so.
        /// </summary>
        /// <param name="player">The player object</param>
        /// <param name="trigger">The trigger or placeable being used/entered.</param>
        private static void HandleTriggerAndPlaceableQuestLogic(NWPlayer player, NWObject trigger)
        {
            if (!player.IsPlayer)
            {
                return;
            }
            string questMessage       = trigger.GetLocalString("QUEST_MESSAGE");
            int    questID            = trigger.GetLocalInt("QUEST_ID");
            int    questState         = trigger.GetLocalInt("QUEST_STATE");
            string visibilityObjectID = trigger.GetLocalString("VISIBILITY_OBJECT_ID");

            if (questID <= 0)
            {
                player.SendMessage("QUEST_ID variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            if (questState <= 0)
            {
                player.SendMessage("QUEST_STATE variable not set on object. Please inform admin this quest is bugged. (QuestID: " + questID + ")");
                return;
            }

            PCQuestStatus pcQuestStatus = DataService.PCQuestStatus.GetByPlayerAndQuestIDOrDefault(player.GlobalID, questID);

            if (pcQuestStatus == null)
            {
                return;
            }


            if (pcQuestStatus.QuestState != questState)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(questMessage))
            {
                DelayCommand(1.0f, () =>
                {
                    player.SendMessage(questMessage);
                });
            }

            var quest = GetQuestByID(questID);

            quest.Advance(player, trigger);

            if (!string.IsNullOrWhiteSpace(visibilityObjectID))
            {
                ObjectVisibilityService.AdjustVisibility(player, trigger, false);
            }
        }
Ejemplo n.º 3
0
        private static void SpawnResources(NWArea area, AreaSpawn areaSpawn)
        {
            var dbArea = DataService.Area.GetByResref(area.Resref);

            if (dbArea.ResourceSpawnTableID <= 0 ||
                !dbArea.AutoSpawnResources)
            {
                return;
            }
            var possibleSpawns = DataService.SpawnObject.GetAllBySpawnTableID(dbArea.ResourceSpawnTableID).ToList();

            // 1024 size = 32x32
            // 256  size = 16x16
            // 64   size = 8x8
            int size = area.Width * area.Height;

            int maxSpawns = 0;

            if (size <= 12)
            {
                maxSpawns = 2;
            }
            else if (size <= 32)
            {
                maxSpawns = 6;
            }
            else if (size <= 64)
            {
                maxSpawns = 10;
            }
            else if (size <= 256)
            {
                maxSpawns = 25;
            }
            else if (size <= 512)
            {
                maxSpawns = 40;
            }
            else if (size <= 1024)
            {
                maxSpawns = 50;
            }

            int[] weights = new int[possibleSpawns.Count()];
            for (int x = 0; x < possibleSpawns.Count(); x++)
            {
                weights[x] = possibleSpawns.ElementAt(x).Weight;
            }

            for (int x = 1; x <= maxSpawns; x++)
            {
                int         index    = RandomService.GetRandomWeightedIndex(weights);
                var         dbSpawn  = possibleSpawns.ElementAt(index);
                Location    location = GetRandomSpawnPoint(area);
                NWPlaceable plc      = (CreateObject(OBJECT_TYPE_PLACEABLE, dbSpawn.Resref, location));
                ObjectSpawn spawn    = new ObjectSpawn(location, false, dbArea.ResourceSpawnTableID, 600.0f);
                spawn.Spawn = plc;

                ObjectVisibilityService.ApplyVisibilityForObject(plc);

                if (dbSpawn.NPCGroupID != null && dbSpawn.NPCGroupID > 0)
                {
                    plc.SetLocalInt("NPC_GROUP", Convert.ToInt32(dbSpawn.NPCGroupID));
                    spawn.NPCGroupID = Convert.ToInt32(dbSpawn.NPCGroupID);
                }

                if (!string.IsNullOrWhiteSpace(dbSpawn.BehaviourScript) &&
                    string.IsNullOrWhiteSpace(plc.GetLocalString("BEHAVIOUR")))
                {
                    plc.SetLocalString("BEHAVIOUR", dbSpawn.BehaviourScript);
                    spawn.BehaviourScript = dbSpawn.BehaviourScript;
                }

                if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule))
                {
                    var rule = GetSpawnRule(dbSpawn.SpawnRule);
                    rule.Run(plc);
                }

                areaSpawn.Placeables.Add(spawn);
            }
        }
Ejemplo n.º 4
0
        private static void ProcessSpawn(ObjectSpawn spawn, int objectType, NWArea area, bool forceSpawn)
        {
            // Don't process anything that's valid.
            if (spawn.Spawn.IsValid)
            {
                return;
            }

            spawn.Timer += ObjectProcessingService.ProcessingTickInterval;

            // Time to respawn!
            if (spawn.Timer >= spawn.RespawnTime || forceSpawn)
            {
                string     resref     = spawn.Resref;
                int        npcGroupID = spawn.NPCGroupID;
                int        deathVFXID = spawn.DeathVFXID;
                string     behaviour  = spawn.BehaviourScript;
                NWLocation location   = spawn.IsStaticSpawnPoint ? spawn.SpawnLocation : null;
                AIFlags    aiFlags    = spawn.AIFlags;

                spawn.HasSpawnedOnce = true;

                // Look for a spawn out of the database set. Update spawn data if one is found.
                if (string.IsNullOrWhiteSpace(resref))
                {
                    var dbSpawn = DataService.SpawnObject.GetAllBySpawnTableID(spawn.SpawnTableID)
                                  .OrderBy(o => Guid.NewGuid()).First();

                    resref     = dbSpawn.Resref;
                    npcGroupID = dbSpawn.NPCGroupID ?? 0;
                    deathVFXID = dbSpawn.DeathVFXID;
                    behaviour  = dbSpawn.BehaviourScript;
                    aiFlags    = dbSpawn.AIFlags;

                    if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule))
                    {
                        spawn.SpawnRule = dbSpawn.SpawnRule;
                    }
                    else
                    {
                        // Clear the saved spawn rule since we now have a new resref etc.
                        spawn.SpawnRule = null;
                    }
                }

                if (location == null)
                {
                    location = GetRandomSpawnPoint(area);
                }

                spawn.Spawn = CreateObject(objectType, resref, location);

                if (!spawn.Spawn.IsValid)
                {
                    Console.WriteLine("SPAWN SERVICE ERROR: Cannot locate object with resref " + resref + ". Error occurred in area " + area.Name + " (" + area.Resref + ")");
                    return;
                }

                if (npcGroupID > 0)
                {
                    spawn.Spawn.SetLocalInt("NPC_GROUP", npcGroupID);
                }

                if (deathVFXID > 0)
                {
                    spawn.Spawn.SetLocalInt("DEATH_VFX", deathVFXID);
                }

                if (!string.IsNullOrWhiteSpace(behaviour) &&
                    string.IsNullOrWhiteSpace(spawn.Spawn.GetLocalString("BEHAVIOUR")))
                {
                    spawn.Spawn.SetLocalString("BEHAVIOUR", behaviour);
                }

                spawn.Spawn.SetLocalInt("AI_FLAGS", (int)aiFlags);

                if (objectType == OBJECT_TYPE_CREATURE)
                {
                    AssignScriptEvents(spawn.Spawn.Object);
                }

                if (!string.IsNullOrWhiteSpace(spawn.SpawnRule))
                {
                    var rule = GetSpawnRule(spawn.SpawnRule);
                    rule.Run(spawn.Spawn);
                }

                ObjectVisibilityService.ApplyVisibilityForObject(spawn.Spawn);

                spawn.Timer = 0.0f;
            }
        }
Ejemplo n.º 5
0
        private static void ProcessSpawn(ObjectSpawn spawn, ObjectType objectType, NWArea area, bool forceSpawn)
        {
            // Spawn expiry.
            if (spawn.Expires < DateTime.UtcNow)
            {
                NWPlaceable prop = spawn.Spawn.GetLocalObject("RESOURCE_PROP_OBJ");
                if (prop.IsValid)
                {
                    DestroyObject(prop);
                }

                DestroyObject(spawn.Spawn);
                forceSpawn = true;
            }
            // Don't process anything that's valid.  Put this in an else branch as object destruction
            // happens after script completion.
            else if (spawn.Spawn.IsValid)
            {
                return;
            }

            spawn.Timer += ObjectProcessingService.ProcessingTickInterval;

            // Time to respawn!
            if (spawn.Timer >= spawn.RespawnTime || forceSpawn)
            {
                string     resref     = spawn.Resref;
                int        npcGroupID = spawn.NPCGroupID;
                int        deathVFXID = spawn.DeathVFXID;
                string     behaviour  = spawn.BehaviourScript;
                NWLocation location   = spawn.IsStaticSpawnPoint ? spawn.SpawnLocation : null;
                AIFlags    aiFlags    = spawn.AIFlags;

                spawn.HasSpawnedOnce = true;

                // Look for a spawn out of the database set. Update spawn data if one is found.
                if (string.IsNullOrWhiteSpace(resref))
                {
                    var dbSpawn = DataService.SpawnObject.GetAllBySpawnTableID(spawn.SpawnTableID)
                                  .OrderBy(o => Guid.NewGuid()).First();

                    resref     = dbSpawn.Resref;
                    npcGroupID = dbSpawn.NPCGroupID ?? 0;
                    deathVFXID = dbSpawn.DeathVFXID;
                    behaviour  = dbSpawn.BehaviourScript;
                    aiFlags    = dbSpawn.AIFlags;

                    if (!string.IsNullOrWhiteSpace(dbSpawn.SpawnRule))
                    {
                        spawn.SpawnRule = dbSpawn.SpawnRule;
                    }
                    else
                    {
                        // Clear the saved spawn rule since we now have a new resref etc.
                        spawn.SpawnRule = null;
                    }
                }

                if (location == null)
                {
                    location = GetRandomSpawnPoint(area);
                }

                spawn.Spawn = CreateObject(objectType, resref, location);

                if (!spawn.Spawn.IsValid)
                {
                    Console.WriteLine("SPAWN SERVICE ERROR: Cannot locate object with resref " + resref + ". Error occurred in area " + area.Name + " (" + area.Resref + ")");
                    return;
                }

                if (npcGroupID > 0)
                {
                    spawn.Spawn.SetLocalInt("NPC_GROUP", npcGroupID);
                }

                if (deathVFXID > 0)
                {
                    spawn.Spawn.SetLocalInt("DEATH_VFX", deathVFXID);
                }

                if (!string.IsNullOrWhiteSpace(behaviour) &&
                    string.IsNullOrWhiteSpace(spawn.Spawn.GetLocalString("BEHAVIOUR")))
                {
                    spawn.Spawn.SetLocalString("BEHAVIOUR", behaviour);
                }

                spawn.Spawn.SetLocalInt("AI_FLAGS", (int)aiFlags);

                // Set expiry time for spawn.  Set creatures to 26 hours (i.e. longer than the server reset
                // cycle, so never).  Set placeables to 1 hour, so blocking objects will move and resources
                // will reset.
                if (objectType == ObjectType.Creature)
                {
                    AssignScriptEvents(spawn.Spawn.Object);
                    spawn.Expires = DateTime.UtcNow.AddHours(26);
                }
                else
                {
                    spawn.Expires = DateTime.UtcNow.AddHours(1);
                }

                if (!string.IsNullOrWhiteSpace(spawn.SpawnRule))
                {
                    var rule = GetSpawnRule(spawn.SpawnRule);
                    rule.Run(spawn.Spawn);
                }

                ObjectVisibilityService.ApplyVisibilityForObject(spawn.Spawn);

                spawn.Timer = 0.0f;
            }
        }