Inheritance: MonoBehaviour
 public void ResetData()
 {
     speech       = null;
     triggerSound = null;
     weaponData   = null;
     objectToSet  = null;
     interactUI.SetActive(false);
 }
Example #2
0
    /// <summary>
    /// Use the gun and return if the gun fired
    /// </summary>
    /// <returns></returns>
    public override bool Use()
    {
        TriggerSound.Play();

        if (!CanShoot())
        {
            ScenarioLogs.logs.Add(new LoggedShot(this, true));
            return(false);
        }

        ShotSound.Play();
        DetectHit();

        currentAmmo--;

        GetComponentInChildren <ParticleSystem>().Play();
        anim.Play("Fire");

        ScenarioLogs.logs.Add(new LoggedShot(this, true));
        return(true);
    }
Example #3
0
        public FieldManager(Player player)
        {
            MapId       = player.MapId;
            InstanceId  = player.InstanceId;
            BoundingBox = MapEntityStorage.GetBoundingBox(MapId);
            // Load default npcs for map from config
            foreach (MapNpc npc in MapEntityStorage.GetNpcs(MapId))
            {
                IFieldObject <Npc> fieldNpc = RequestFieldObject(new Npc(npc.Id)
                {
                    ZRotation = (short)(npc.Rotation.Z * 10)
                });

                if (fieldNpc.Value.Friendly == 2)
                {
                    fieldNpc.Coord = npc.Coord.ToFloat();
                    AddNpc(fieldNpc);
                }
                else
                {
                    // NPC is an enemy
                    IFieldObject <Mob> fieldMob = RequestFieldObject(new Mob(npc.Id)
                    {
                        ZRotation = (short)(npc.Rotation.Z * 10)
                    });

                    fieldMob.Coord = npc.Coord.ToFloat();
                    AddMob(fieldMob);
                }
            }

            // Spawn map's mobs at the mob spawners
            foreach (MapMobSpawn mobSpawn in MapEntityStorage.GetMobSpawns(MapId))
            {
                if (mobSpawn.SpawnData == null)
                {
                    Debug.WriteLine($"Missing mob spawn data: {mobSpawn}");
                    continue;
                }
                IFieldObject <MobSpawn> fieldMobSpawn = RequestFieldObject(new MobSpawn(mobSpawn));
                fieldMobSpawn.Coord = mobSpawn.Coord.ToFloat();
                State.AddMobSpawn(fieldMobSpawn);
                SpawnMobs(fieldMobSpawn);
            }

            // Load default portals for map from config
            foreach (MapPortal portal in MapEntityStorage.GetPortals(MapId))
            {
                IFieldObject <Portal> fieldPortal = RequestFieldObject(new Portal(portal.Id)
                {
                    IsVisible        = portal.IsVisible,
                    IsEnabled        = portal.Enable,
                    IsMinimapVisible = portal.MinimapVisible,
                    Rotation         = portal.Rotation.ToFloat(),
                    TargetMapId      = portal.Target,
                    TargetPortalId   = portal.TargetPortalId,
                    PortalType       = portal.PortalType
                });
                fieldPortal.Coord = portal.Coord.ToFloat();
                AddPortal(fieldPortal);
            }

            MapMetadata mapMetadata = MapMetadataStorage.GetMetadata(MapId);

            if (mapMetadata != null)
            {
                string xBlockName = mapMetadata.XBlockName;
                Triggers = TriggerLoader.GetTriggers(xBlockName).Select(initializer =>
                {
                    TriggerContext context  = new TriggerContext(this, Logger);
                    TriggerState startState = initializer.Invoke(context);
                    return(new TriggerScript(context, startState));
                }).ToArray();
            }

            foreach (MapTriggerMesh mapTriggerMesh in MapEntityStorage.GetTriggerMeshes(MapId))
            {
                if (mapTriggerMesh != null)
                {
                    TriggerMesh triggerMesh = new TriggerMesh(mapTriggerMesh.Id, mapTriggerMesh.IsVisible);
                    State.AddTriggerObject(triggerMesh);
                }
            }

            foreach (MapTriggerEffect mapTriggerEffect in MapEntityStorage.GetTriggerEffects(MapId))
            {
                if (mapTriggerEffect != null)
                {
                    TriggerEffect triggerEffect = new TriggerEffect(mapTriggerEffect.Id, mapTriggerEffect.IsVisible);
                    State.AddTriggerObject(triggerEffect);
                }
            }

            foreach (MapTriggerActor mapTriggerActor in MapEntityStorage.GetTriggerActors(MapId))
            {
                if (mapTriggerActor != null)
                {
                    TriggerActor triggerActor = new TriggerActor(mapTriggerActor.Id, mapTriggerActor.IsVisible, mapTriggerActor.InitialSequence);
                    State.AddTriggerObject(triggerActor);
                }
            }

            foreach (MapTriggerCamera mapTriggerCamera in MapEntityStorage.GetTriggerCameras(MapId))
            {
                if (mapTriggerCamera != null)
                {
                    TriggerCamera triggerCamera = new TriggerCamera(mapTriggerCamera.Id, mapTriggerCamera.IsEnabled);
                    State.AddTriggerObject(triggerCamera);
                }
            }

            foreach (MapTriggerCube mapTriggerCube in MapEntityStorage.GetTriggerCubes(MapId))
            {
                if (mapTriggerCube != null)
                {
                    TriggerCube triggerCube = new TriggerCube(mapTriggerCube.Id, mapTriggerCube.IsVisible);
                    State.AddTriggerObject(triggerCube);
                }
            }

            foreach (MapTriggerLadder mapTriggerLadder in MapEntityStorage.GetTriggerLadders(MapId))
            {
                if (mapTriggerLadder != null)
                {
                    TriggerLadder triggerLadder = new TriggerLadder(mapTriggerLadder.Id, mapTriggerLadder.IsVisible);
                    State.AddTriggerObject(triggerLadder);
                }
            }

            foreach (MapTriggerRope mapTriggerRope in MapEntityStorage.GetTriggerRopes(MapId))
            {
                if (mapTriggerRope != null)
                {
                    TriggerRope triggerRope = new TriggerRope(mapTriggerRope.Id, mapTriggerRope.IsVisible);
                    State.AddTriggerObject(triggerRope);
                }
            }

            foreach (MapTriggerSound mapTriggerSound in MapEntityStorage.GetTriggerSounds(MapId))
            {
                if (mapTriggerSound != null)
                {
                    TriggerSound triggerSound = new TriggerSound(mapTriggerSound.Id, mapTriggerSound.IsEnabled);
                    State.AddTriggerObject(triggerSound);
                }
            }

            foreach (MapTriggerSkill mapTriggerSkill in MapEntityStorage.GetTriggerSkills(MapId))
            {
                if (mapTriggerSkill != null)
                {
                    TriggerSkill triggerSkill = new TriggerSkill(mapTriggerSkill.Id, mapTriggerSkill.SkillId, mapTriggerSkill.SkillLevel, mapTriggerSkill.Count, mapTriggerSkill.Position);
                    IFieldObject <TriggerSkill> fieldTriggerSkill = RequestFieldObject(triggerSkill);
                    fieldTriggerSkill.Coord = fieldTriggerSkill.Value.Position;

                    State.AddTriggerSkills(fieldTriggerSkill);
                }
            }

            // Load breakables
            foreach (MapBreakableActorObject mapActor in MapEntityStorage.GetBreakableActors(MapId))
            {
                if (mapActor != null)
                {
                    BreakableActorObject actor = new BreakableActorObject(mapActor.EntityId, mapActor.IsEnabled, mapActor.HideDuration, mapActor.ResetDuration);
                    State.AddBreakable(actor);
                }
            }

            foreach (MapBreakableNifObject mapNif in MapEntityStorage.GetBreakableNifs(MapId))
            {
                if (mapNif != null)
                {
                    BreakableNifObject nif = new BreakableNifObject(mapNif.EntityId, mapNif.IsEnabled, mapNif.TriggerId, mapNif.HideDuration, mapNif.ResetDuration);
                    State.AddBreakable(nif);
                }
            }

            // Load interact objects
            foreach (MapInteractObject mapInteract in MapEntityStorage.GetInteractObjects(MapId))
            {
                if (mapInteract != null)
                {
                    InteractObject interactObject = new InteractObject(mapInteract.EntityId, mapInteract.InteractId, mapInteract.Type, InteractObjectState.Default);
                    State.AddInteractObject(interactObject);
                }
            }

            // Load cubes
            if (MapId == (int)Map.PrivateResidence)
            {
                Home home = GameServer.HomeManager.GetHomeById(player.VisitingHomeId);
                if (home != null)
                {
                    // Add cubes to state
                    Dictionary <long, Cube> cubes = home.FurnishingInventory;
                    foreach (Cube cube in cubes.Values.Where(x => x.PlotNumber == 1))
                    {
                        IFieldObject <Cube> ugcCube = RequestFieldObject(cube);
                        ugcCube.Coord    = cube.CoordF;
                        ugcCube.Rotation = cube.Rotation;
                        State.AddCube(ugcCube);
                    }

                    // Add portals to state
                    IEnumerable <Cube> cubePortals = cubes.Values.Where(x => x.Item.Id == 50400158);
                    foreach (Cube cubePortal in cubePortals)
                    {
                        Portal portal = new Portal(GuidGenerator.Int())
                        {
                            IsVisible        = true,
                            IsEnabled        = true,
                            IsMinimapVisible = false,
                            Rotation         = cubePortal.Rotation,
                            PortalType       = PortalTypes.Home
                        };

                        IFieldObject <Portal> fieldPortal = RequestFieldObject(portal);
                        fieldPortal.Coord = cubePortal.CoordF;
                        fieldPortal.Value.UGCPortalMethod = cubePortal.PortalSettings.Method;
                        if (!string.IsNullOrEmpty(cubePortal.PortalSettings.DestinationTarget))
                        {
                            switch (cubePortal.PortalSettings.Destination)
                            {
                            case UGCPortalDestination.PortalInHome:
                                fieldPortal.Value.TargetMapId = (int)Map.PrivateResidence;
                                break;

                            case UGCPortalDestination.SelectedMap:
                                fieldPortal.Value.TargetMapId = int.Parse(cubePortal.PortalSettings.DestinationTarget);
                                break;

                            case UGCPortalDestination.FriendHome:
                                fieldPortal.Value.TargetHomeAccountId = long.Parse(cubePortal.PortalSettings.DestinationTarget);
                                break;
                            }
                        }
                        cubePortal.PortalSettings.PortalObjectId = fieldPortal.ObjectId;
                        AddPortal(fieldPortal);
                    }
                }
            }
            else
            {
                List <Home> homes = GameServer.HomeManager.GetPlots(MapId);
                foreach (Home home in homes)
                {
                    Dictionary <long, Cube> cubes = home.FurnishingInventory;
                    foreach (Cube cube in cubes.Values.Where(x => x.PlotNumber != 1))
                    {
                        IFieldObject <Cube> ugcCube = RequestFieldObject(cube);
                        ugcCube.Coord    = cube.CoordF;
                        ugcCube.Rotation = cube.Rotation;
                        State.AddCube(ugcCube);
                    }
                }
            }

            if (MapEntityStorage.HasHealingSpot(MapId))
            {
                List <CoordS> healingSpots = MapEntityStorage.GetHealingSpot(MapId);
                if (State.HealingSpots.IsEmpty)
                {
                    foreach (CoordS coord in healingSpots)
                    {
                        int objectId = GuidGenerator.Int();
                        State.AddHealingSpot(RequestFieldObject(new HealingSpot(objectId, coord)));
                    }
                }
            }
        }
        public FieldManager(int mapId, long instanceId)
        {
            MapId       = mapId;
            InstanceId  = instanceId;
            BoundingBox = MapEntityStorage.GetBoundingBox(mapId);
            // Load default npcs for map from config
            foreach (MapNpc npc in MapEntityStorage.GetNpcs(mapId))
            {
                IFieldObject <Npc> fieldNpc = RequestFieldObject(new Npc(npc.Id)
                {
                    ZRotation = (short)(npc.Rotation.Z * 10)
                });

                if (fieldNpc.Value.Friendly == 2)
                {
                    fieldNpc.Coord = npc.Coord.ToFloat();
                    AddNpc(fieldNpc);
                }
                else
                {
                    // NPC is an enemy
                    IFieldObject <Mob> fieldMob = RequestFieldObject(new Mob(npc.Id)
                    {
                        ZRotation = (short)(npc.Rotation.Z * 10)
                    });

                    fieldMob.Coord = npc.Coord.ToFloat();
                    AddMob(fieldMob);
                }
            }

            // Spawn map's mobs at the mob spawners
            foreach (MapMobSpawn mobSpawn in MapEntityStorage.GetMobSpawns(mapId))
            {
                if (mobSpawn.SpawnData == null)
                {
                    Debug.WriteLine($"Missing mob spawn data: {mobSpawn}");
                    continue;
                }
                IFieldObject <MobSpawn> fieldMobSpawn = RequestFieldObject(new MobSpawn(mobSpawn));
                fieldMobSpawn.Coord = mobSpawn.Coord.ToFloat();
                State.AddMobSpawn(fieldMobSpawn);
                SpawnMobs(fieldMobSpawn);
            }

            // Load default portals for map from config
            foreach (MapPortal portal in MapEntityStorage.GetPortals(mapId))
            {
                IFieldObject <Portal> fieldPortal = RequestFieldObject(new Portal(portal.Id)
                {
                    IsVisible        = portal.IsVisible,
                    IsEnabled        = portal.Enable,
                    IsMinimapVisible = portal.MinimapVisible,
                    Rotation         = portal.Rotation.ToFloat(),
                    TargetMapId      = portal.Target,
                    PortalType       = portal.PortalType
                });
                fieldPortal.Coord = portal.Coord.ToFloat();
                AddPortal(fieldPortal);
            }

            // Load default InteractObjects
            List <IFieldObject <InteractObject> > actors = new List <IFieldObject <InteractObject> > {
            };

            foreach (MapInteractObject interactObject in MapEntityStorage.GetInteractObject(mapId))
            {
                // TODO: Group these fieldActors by their correct packet type.
                actors.Add(RequestFieldObject(new InteractObject(interactObject.Uuid, interactObject.Name, interactObject.Type)
                {
                }));
            }
            AddInteractObject(actors);

            MapMetadata mapMetadata = MapMetadataStorage.GetMetadata(mapId);

            if (mapMetadata != null)
            {
                string xBlockName = mapMetadata.XBlockName;
                Triggers = TriggerLoader.GetTriggers(xBlockName).Select(initializer =>
                {
                    TriggerContext context  = new TriggerContext(this, Logger);
                    TriggerState startState = initializer.Invoke(context);
                    return(new TriggerScript(context, startState));
                }).ToArray();
            }

            foreach (MapTriggerMesh mapTriggerMesh in MapEntityStorage.GetTriggerMeshes(mapId))
            {
                if (mapTriggerMesh != null)
                {
                    TriggerMesh triggerMesh = new TriggerMesh(mapTriggerMesh.Id, mapTriggerMesh.IsVisible);
                    State.AddTriggerObject(triggerMesh);
                }
            }

            foreach (MapTriggerEffect mapTriggerEffect in MapEntityStorage.GetTriggerEffects(mapId))
            {
                if (mapTriggerEffect != null)
                {
                    TriggerEffect triggerEffect = new TriggerEffect(mapTriggerEffect.Id, mapTriggerEffect.IsVisible);
                    State.AddTriggerObject(triggerEffect);
                }
            }

            foreach (MapTriggerActor mapTriggerActor in MapEntityStorage.GetTriggerActors(mapId))
            {
                if (mapTriggerActor != null)
                {
                    TriggerActor triggerActor = new TriggerActor(mapTriggerActor.Id, mapTriggerActor.IsVisible, mapTriggerActor.InitialSequence);
                    State.AddTriggerObject(triggerActor);
                }
            }

            foreach (MapTriggerCamera mapTriggerCamera in MapEntityStorage.GetTriggerCameras(mapId))
            {
                if (mapTriggerCamera != null)
                {
                    TriggerCamera triggerCamera = new TriggerCamera(mapTriggerCamera.Id, mapTriggerCamera.IsEnabled);
                    State.AddTriggerObject(triggerCamera);
                }
            }

            foreach (MapTriggerCube mapTriggerCube in MapEntityStorage.GetTriggerCubes(mapId))
            {
                if (mapTriggerCube != null)
                {
                    TriggerCube triggerCube = new TriggerCube(mapTriggerCube.Id, mapTriggerCube.IsVisible);
                    State.AddTriggerObject(triggerCube);
                }
            }

            foreach (MapTriggerLadder mapTriggerLadder in MapEntityStorage.GetTriggerLadders(mapId))
            {
                if (mapTriggerLadder != null)
                {
                    TriggerLadder triggerLadder = new TriggerLadder(mapTriggerLadder.Id, mapTriggerLadder.IsVisible);
                    State.AddTriggerObject(triggerLadder);
                }
            }

            foreach (MapTriggerRope mapTriggerRope in MapEntityStorage.GetTriggerRopes(mapId))
            {
                if (mapTriggerRope != null)
                {
                    TriggerRope triggerRope = new TriggerRope(mapTriggerRope.Id, mapTriggerRope.IsVisible);
                    State.AddTriggerObject(triggerRope);
                }
            }

            foreach (MapTriggerSound mapTriggerSound in MapEntityStorage.GetTriggerSounds(mapId))
            {
                if (mapTriggerSound != null)
                {
                    TriggerSound triggerSound = new TriggerSound(mapTriggerSound.Id, mapTriggerSound.IsEnabled);
                    State.AddTriggerObject(triggerSound);
                }
            }

            // Load breakables
            foreach (MapBreakableActorObject mapActor in MapEntityStorage.GetBreakableActors(mapId))
            {
                if (mapActor != null)
                {
                    BreakableActorObject actor = new BreakableActorObject(mapActor.EntityId, mapActor.IsEnabled, mapActor.HideDuration, mapActor.ResetDuration);
                    State.AddBreakable(actor);
                }
            }

            foreach (MapBreakableNifObject mapNif in MapEntityStorage.GetBreakableNifs(mapId))
            {
                if (mapNif != null)
                {
                    BreakableNifObject nif = new BreakableNifObject(mapNif.EntityId, mapNif.IsEnabled, mapNif.TriggerId, mapNif.HideDuration, mapNif.ResetDuration);
                    State.AddBreakable(nif);
                }
            }

            if (MapEntityStorage.HasHealingSpot(MapId))
            {
                List <CoordS> healingSpots = MapEntityStorage.GetHealingSpot(MapId);
                if (State.HealingSpots.IsEmpty)
                {
                    foreach (CoordS coord in healingSpots)
                    {
                        int objectId = GuidGenerator.Int();
                        State.AddHealingSpot(RequestFieldObject(new HealingSpot(objectId, coord)));
                    }
                }
            }
        }
    private void OnTriggerEnter(Collider collision)
    {
        //Speech trigger
        if (collision.tag[0] == '1')
        {
            speech = collision.GetComponent <Speech>();

            SetObjects(collision);

            if (speech.speechType == TriggerType.AutoTrigger)
            {
                SpeechTrigger();
            }
            else
            {
                interactUI.SetActive(true);
            }
        }
        //Tutorial trigger
        else if (collision.tag[0] == '2')
        {
            var tutorial = collision.GetComponent <Tutorial>();

            tutorial.tutorial.SetActive(true);
        }
        //Audio trigger
        else if (collision.tag[0] == '3')
        {
            triggerSound = collision.GetComponent <TriggerSound>();

            SetObjects(collision);

            if (triggerSound.triggerType == TriggerType.AutoTrigger)
            {
                AudioTrigger();
            }
            else
            {
                interactUI.SetActive(true);
            }
        }
        //Pickup item
        else if (collision.tag[0] == '4')
        {
            weaponData = collision.GetComponent <WeaponData>();

            if (weaponData.triggerType == TriggerType.AutoTrigger)
            {
                PickUpWeapon();
            }
            else
            {
                interactUI.SetActive(true);
            }
        }
        //Pickup Ammo
        else if (collision.tag[0] == '6')
        {
            Ammo(collision.GetComponent <Ammo>());
        }
        //Pickup Medikit
        else if (collision.tag[0] == '8')
        {
            Heal(collision.GetComponent <MediData>());
        }
        else if (collision.tag[0] == 'f')
        {
            trapDoorTrigger.EnableFinalStage();
        }
    }
Example #6
0
        public static GameObject Instantiate(ENTITY e)
        {
            GameObject entityObject;

            switch (e.Classname)
            {
            case "action_animate":
            {
                entityObject = AnimateAction.Instantiate(e);
                break;
            }

            case "action_move":
            {
                entityObject = MoveAction.Instantiate(e);
                break;
            }

            case "action_rotate":
            {
                entityObject = RotateAction.Instantiate(e);
                break;
            }

            case "action_sequence":
            {
                entityObject = ActionSequence.Instantiate(e);
                break;
            }

            case "action_sound":
            {
                entityObject = SoundAction.Instantiate(e);
                break;
            }

            case "action_wait":
            {
                entityObject = WaitAction.Instantiate(e);
                break;
            }

            case "audio_source":
            {
                entityObject = AudioSourceObject.Instantiate(e);
                break;
            }

            case "dream_environment":
            {
                entityObject = DreamEnvironment.Instantiate(e);
                break;
            }

            case "!map":
            {
                entityObject = MapObject.Instantiate(e);
                break;
            }

            case "!model":
            {
                entityObject = ModelObject.Instantiate(e);
                break;
            }

            case "music_controller":
            {
                entityObject = MusicController.Instantiate(e);
                break;
            }

            case "player_spawn":
            {
                entityObject = PlayerSpawn.Instantiate(e);
                break;
            }

            case "target":
            {
                entityObject = Target.Instantiate(e);
                break;
            }

            case "trigger_link":
            {
                entityObject = TriggerLink.Instantiate(e);
                break;
            }

            case "trigger_sequence":
            {
                entityObject = TriggerSequence.Instantiate(e);
                break;
            }

            case "trigger_sound":
            {
                entityObject = TriggerSound.Instantiate(e);
                break;
            }

            case "trigger_teleport":
            {
                entityObject = TriggerTeleport.Instantiate(e);
                break;
            }

            default:
            {
                Debug.LogWarning("Could not instantiate entity with classname " + e.Classname);
                entityObject = new GameObject(e.Classname);
                break;
            }
            }

            return(entityObject);
        }