Ejemplo n.º 1
0
 public override void Interact(CharacterInteraction target)
 {
     if (target.CurrentHeldItem != null && target.CurrentHeldItem is BarrelPickup)
     {
         target.Equipment.PlaceItem(transform.position, transform.rotation, transform);
     }
 }
Ejemplo n.º 2
0
    void Dialogue()
    {
        CharacterInteraction nearest = null;
        float nearDist = 9999f;


        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, _radiusint);
        Debug.Log(colliders.Length);
        var characters = from collider in colliders
                         where collider.GetComponent <CharacterInteraction>() != null
                         select collider.GetComponent <CharacterInteraction>();

        Debug.Log(characters.Count());
        //characters.Min(char1=> Vector2.Distance(transform.position, char1.transform.position));
        foreach (CharacterInteraction cr in characters)
        {
            float thisDist = (transform.position - cr.transform.position).sqrMagnitude;
            if (thisDist < nearDist)
            {
                nearDist = thisDist;
                nearest  = cr;
            }
            Debug.Log(nearDist);
        }

        if (nearest != null)
        {
            nearest.DialogueTrigger.TriggerDialogue();
        }
    }
Ejemplo n.º 3
0
    public override void Interact(CharacterInteraction target)
    {
        // Connecting the cable
        if (target.CurrentHeldItem != null && target.CurrentHeldItem is PowerPlug)
        {
            target.Equipment.PlaceItem(plugPivotPoint.position, plugPivotPoint.rotation, plugPivotPoint);
            connectedPlug = (PowerPlug)target.CurrentHeldItem;
            if (connectedPlug != null)
            {
                connectedPlug.SetConnectedSocket(this);
                connectedPlug.SendRefreshSignal(this);
                //connectedPlug.FindGenerators(this);
            }
            connectedConduit.FindGenerators();
        }

        // Disconnecting the cable
        if (target.CurrentHeldItem == null && connectedPlug != null)
        {
            connectedPlug.ResetComponents();
            connectedPlug.Interact(target);
            connectedPlug.RemoveGenerator(connectedConduit.powerSource, this);
            connectedPlug.SetConnectedSocket(null);
            connectedPlug.SendRefreshSignal(this);
            //connectedPlug.FindGenerators(this);
            connectedPlug = null;
            connectedConduit.FindGenerators();
            connectedConduit.SendRefreshSignal();
        }
    }
Ejemplo n.º 4
0
 public void OnInteract(CharacterInteraction instigator)
 {
     if (_holdState == HoldState.Dropped)
     {
         Pickup();
         instigator.InventoryComponent.AddHoldable(this);
     }
 }
Ejemplo n.º 5
0
 public override void Interact(CharacterInteraction tar)
 {
     if (orb == null)
     {
         orb = GetComponent <ObjectOrientation>();
     }
     needsMovingToHandle = true;
     base.Interact(tar);
 }
Ejemplo n.º 6
0
 internal override void TemplateAfterAwake()
 {
     base.TemplateAfterAwake();
     GameSuperviser.Instance.AddCharacter(this);
     _MoveComponent          = gameObject.AddComponent <CharacterMove>();
     _VisualizationComponent = gameObject.AddComponent <CharacterVisualization>();
     _InteractionComponent   = gameObject.AddComponent <CharacterInteraction>();
     gameObject.AddComponent <CharacterInputHandler>();
 }
 private void CreateInstance()
 {
     if (Instance != null && Instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         Instance = this;
     }
 }
Ejemplo n.º 8
0
 private void Start()
 {
     Joystick                       = new Joystick(PlayerNumber);
     _characterController           = GetComponent <CharacterController>();
     _characterInteraction          = GetComponent <CharacterInteraction>();
     _inventory                     = GetComponent <Character.Inventory.Inventory>();
     _characterHealth               = GetComponent <CharacterHealth>();
     _characterLight                = GetComponent <CharacterLight>();
     _characterHealth.HealthChange += Notify;
     _inventory.InventoryChange    += Notify;
 }
Ejemplo n.º 9
0
 void Start()
 {
     // Add components to character
     _characterMovement    = gameObject.AddComponent <CharacterMovement>() as CharacterMovement;
     _characterTimer       = gameObject.AddComponent <CharacterTimer>() as CharacterTimer;
     _characterInteraction = gameObject.AddComponent <CharacterInteraction>() as CharacterInteraction;
     _characterInventory   = gameObject.AddComponent <CharacterInventory>() as CharacterInventory;
     _characterDialogue    = gameObject.AddComponent <CharacterDialogue>() as CharacterDialogue;
     // Assign default values
     _characterMovement.CharacterPhysicalObject = _characterPhysicalObject;
     _characterTimer.StartTime = _startTime;
 }
Ejemplo n.º 10
0
 private void InteractWithCharacter()
 {
     if (Input.GetKeyDown(KeyCode.R))
     {
         //Si en la dirección del próximo movimiento hay un collider del layer definido como obstáculo no se puede mover
         RaycastHit2D rHitCharacter = Physics2D.Raycast(rayOrigin.position, direccionRayo, tamanioCasilla / 2.0f, layerCharacter);
         if (rHitCharacter)
         {
             CharacterInteraction character = rHitCharacter.collider.gameObject.GetComponent <CharacterInteraction>();
             character.Interact();
         }
     }
 }
Ejemplo n.º 11
0
    private void Awake()
    {
        if (instance != null)
        {
            Destroy(instance);
        }
        else
        {
            instance = this;
        }

        animator = GetComponent <Animator>();
    }
Ejemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        if (!sporeShotSource)
        {
            sporeShotSource = transform.FindChild("SporeShotSource").gameObject;
        }

        rayMovement          = GetComponent <RayMovement>();
        characterInteraction = GetComponent <CharacterInteraction>();

        ui = GameObject.FindGameObjectWithTag("UI");
        triggerIndicator = ui.transform.FindChild("TriggerIndicator").gameObject;

        cameras = FindObjectOfType <CameraController>();
    }
Ejemplo n.º 13
0
    //Spawns characters in character spawnpoints
    private void AssignCharactersToSpawnPoints(Scene scene)
    {
        int spawnPointCounter = 0;

        if (scene.GetCharacters().Count > 0)          //Checks if there are characters to spawn
        {
            foreach (NonPlayerCharacter character in scene.GetCharacters())
            {
                GameObject prefab = Instantiate(character.GetPrefab(), characterSpawnPoints [spawnPointCounter].transform.position, Quaternion.identity) as GameObject; //Spawns the character prefab at the position of the given spawnpoint
                prefab.transform.localScale *= characterScaling;                                                                                                        //Scales the character relative to characterScaling
                spawnPointCounter           += 1;
                CharacterInteraction characterInteraction = prefab.GetComponent <CharacterInteraction> ();
                characterInteraction.SetCharacter(character);                                           //Tells the prefab which character it is
            }
        }
    }
Ejemplo n.º 14
0
    public void OnInteract(CharacterInteraction instigator)
    {
        Dictionary <Constants.Resource.ResourceType, GameResource> availableResources = new Dictionary <Constants.Resource.ResourceType, GameResource> ();

        // Note: If it where possible for multiple instances of resources to be on the map at once, the order
        //  that the next two sections are in will determine if resources are used out of the player's inventory
        //  first, or off the ground first.

        // Find nearby resources
        List <GameResource> nearbyResources = GameManager.Instance.GetResourcesInRange(instigator.transform, instigator.interactDistance);

        foreach (GameResource gr in nearbyResources)
        {
            availableResources[gr.type] = gr; // This is set to be used
        }

        // Find resources in player inventory
        foreach (GameResource gr in instigator.InventoryComponent.heldInventory)
        {
            availableResources[gr.type] = gr; // This is set to be used
        }

        bool canRepair = true;

        foreach (Constants.Resource.ResourceType cost in repairCost)
        {
            canRepair = availableResources.ContainsKey(cost);
            if (!canRepair)   // No sense continuing, we can't repair
            {
                return;
            }
        }

        if (canRepair)
        {
            foreach (Constants.Resource.ResourceType cost in repairCost)
            {
                GameManager.Instance.ConsumeResource(availableResources[cost]);
            }
            ChangeHealth(healthRepairAmount);
        }
    }
Ejemplo n.º 15
0
    //Constructor
    // Param 1: name of the data file in string format
    public GameCharacter(string type)
    {
        string fileName = type + ".xml";

        //Get Game Character Data from XML file
        this.getXMLData(fileName);
        //Instantiate CharacterModel class
        this.charModel = new CharacterModel();
        this.getCharacterObject().name = this.characterName;
        //Instantiate CharacterInteraction class
        this.charInteraction = new CharacterInteraction();
        //Set start coordinates of unit (This will depend on scenario later)
        this.charInteraction.x = 5;
        this.charInteraction.z = 5;
        //Set previous Coordinates of unit
        this.charInteraction.backupPosition();
        //Instantiate CharacterAI class
        this.charAI = new CharacterAI();
        //Get instance of ActionMenu class
        this.am = GameObject.Find("actionMenu").GetComponent <ActionMenu>();
    }
Ejemplo n.º 16
0
 public abstract void Interact(CharacterInteraction target);
Ejemplo n.º 17
0
 public override void Interact(CharacterInteraction target)
 {
     myEvent.Invoke();
 }
Ejemplo n.º 18
0
 public override void Interact(CharacterInteraction target)
 {
     OpenMonitorConsole();
 }
Ejemplo n.º 19
0
 private void Awake()
 {
     movementScript      = GetComponent <CharacterMovement>();
     m_interactionScript = GetComponent <CharacterInteraction>();
 }
Ejemplo n.º 20
0
 public override void Interact(CharacterInteraction tar)
 {
     target = tar;
     PickupItem();
 }
Ejemplo n.º 21
0
 public void OnDefocus(CharacterInteraction focuser)
 {
 }
Ejemplo n.º 22
0
 public void Interact(CharacterInteraction target)
 {
     Events.Invoke();
 }
Ejemplo n.º 23
0
 public void Start()
 {
     characterInteraction = GetComponent <CharacterInteraction>();
 }
Ejemplo n.º 24
0
 public void SetupLocal()
 {
     // assign variables that have to do with this class only
     character = CharacterInteraction.use;
 }
Ejemplo n.º 25
0
 // Start is called before the first frame update
 void Start()
 {
     _characterInteraction = CharacterInteraction.Instance;
     _playerTransform      = _characterInteraction.gameObject.transform;
     _interactionUI        = _characterInteraction.InteractionUI;
 }
Ejemplo n.º 26
0
    /// <summary>
    /// Spawns a character based on information from Entity class.
    /// </summary>
    /// <param name="entity">Character to spawn.</param>
    /// <param name="position">Position to spawn the character to.</param>
    /// <returns>Returns the whole character gameobject.</returns>
    GameObject SpawnEntity(int indexOfEntity, Vector3 position = default(Vector3))
    {
        // If character's infection is in its final stage and no time is left, does not spawn this character
        if (allCharacters[indexOfEntity].currentStateOfInfection == CharacterEnums.InfectionState.Final && allCharacters[indexOfEntity].currentInfectionStageDuration <= 0)
        {
            Entity en = allCharacters[indexOfEntity];
            en.isAlive = false;
            return(null);
        }

        // Gets map's width and randomizes x position to be somewhere in the map
        float mapWidth = FindObjectOfType <BackgroundGenerator>().GetBackgroundWidth();
        float xPos     = UnityEngine.Random.Range(-mapWidth / 2, mapWidth / 2);

        // Initiates default spawn position with random x position and -5.9y, because floor is about -6y
        Vector3 spawnPosition = new Vector3(xPos, -5.9f, 0f);

        // Changes position if it is set in parameters
        if (position != default(Vector3))
        {
            spawnPosition = position;
        }

        // Creates the gameobject from prefab with character name
        GameObject go = (GameObject)Instantiate(characterPrefab, spawnPosition, Quaternion.identity);

        go.name = allCharacters[indexOfEntity].character.characterName;

        // If conversation is set, gives it to the spawned character
        if (allCharacters[indexOfEntity].character.VideConversation != null)
        {
            go.GetComponent <VIDE_Assign>().assignedDialogue = allCharacters[indexOfEntity].character.VideConversation;
            go.GetComponent <VIDE_Assign>().assignedIndex    = allCharacters[indexOfEntity].character.VideConversationIndex;
        }

        // If animator is set, gives it to the spawned character
        if (allCharacters[indexOfEntity].character.animator != null)
        {
            go.GetComponentInChildren <Animator>().runtimeAnimatorController = allCharacters[indexOfEntity].character.animator;
        }

        // If pose sprite is set, changes the sprite to that
        // Not probably needed
        //if (character.characterPoseSprite != null)
        //{
        //    go.GetComponentInChildren<SpriteRenderer>().sprite = character.characterPoseSprite;
        //}

        // Gets components to memory for easy access
        Entity               e    = go.GetComponent <Entity>();
        RayNPC               rnpc = go.GetComponent <RayNPC>();
        RayPlayerInput       rpi  = go.GetComponent <RayPlayerInput>();
        CharacterInteraction ci   = go.GetComponent <CharacterInteraction>();

        // Checks if character is currently NPC
        if (allCharacters[indexOfEntity].isNPC)
        {
            // Enables/sets NPC stuff and disables player stuff
            go.transform.SetParent(GameObject.FindGameObjectWithTag("NPC_Container").transform);
            go.tag       = "NPC";
            rnpc.enabled = true;
            rnpc.SetAIBehaviourActive(true);
            rpi.enabled = false;
            ci.enabled  = false;
        }
        else
        {
            // Enables/sets player stuff and disables NPC stuff
            go.transform.parent = FindObjectOfType <AdvancedHivemind>().transform;
            go.tag = "Player";
            rnpc.SetAIBehaviourActive(false);
            rnpc.enabled = false;
            rpi.enabled  = true;
            ci.enabled   = true;
            infectedCharacters.Add(go.GetComponent <Entity>());
            if (allCharacters[indexOfEntity].currentStateOfInfection == CharacterEnums.InfectionState.None)
            {
                allCharacters[indexOfEntity].currentStateOfInfection = CharacterEnums.InfectionState.State1;
            }
        }

        // Updates character's entity class
        CopyEntities(ref e, allCharacters[indexOfEntity]);

        // Adds the entity the lists of entities
        allCharacters[indexOfEntity] = go.GetComponent <Entity>();
        charactersOnLevel.Add(go.GetComponent <Entity>());

        // Hides comment box
        go.transform.GetComponentInChildren <RandomComment>().transform.parent.gameObject.SetActive(false);

        return(go);
    }
Ejemplo n.º 27
0
    GameObject SpawnEntity(Entity entity, Vector3 position = default(Vector3))
    {
        // Initiates default spawn position (-5y because floor is about -6y)
        Vector3 spawnPosition = new Vector3(0f, -5f, 0f);

        // Changes position if it is set in parameters
        if (position != default(Vector3))
        {
            spawnPosition = position;
        }

        // Creates the gameobject from prefab with character name
        GameObject go = (GameObject)Instantiate(characterPrefab, spawnPosition, Quaternion.identity);

        go.name = entity.character.characterName;

        // If conversation is set, gives it to the spawned character
        if (entity.character.VideConversation != null)
        {
            go.GetComponent <VIDE_Assign>().assignedDialogue = entity.character.VideConversation;
            go.GetComponent <VIDE_Assign>().assignedIndex    = entity.character.VideConversationIndex;
        }

        // If animator is set, gives it to the spawned character
        if (entity.character.animator != null)
        {
            go.GetComponentInChildren <Animator>().runtimeAnimatorController = entity.character.animator;
        }

        // If pose sprite is set, changes the sprite to that
        // Not probably needed
        //if (character.characterPoseSprite != null)
        //{
        //    Debug.Log(character.name + " had pose sprite.");
        //    Debug.Log("Changing sprite to " + character.characterPoseSprite.name);
        //    go.GetComponentInChildren<SpriteRenderer>().sprite = character.characterPoseSprite;
        //}

        // Gets components to memory for easy access
        RayNPC               rnpc = go.GetComponent <RayNPC>();
        RayPlayerInput       rpi  = go.GetComponent <RayPlayerInput>();
        CharacterInteraction ci   = go.GetComponent <CharacterInteraction>();

        // Checks if character is currently NPC
        if (entity.isNPC)
        {
            // Enables/sets NPC stuff and disables player stuff
            go.transform.SetParent(GameObject.FindGameObjectWithTag("NPC_Container").transform);
            go.tag       = "NPC";
            rnpc.enabled = true;
            rnpc.SetAIBehaviourActive(true);
            rpi.enabled = false;
            ci.enabled  = false;
        }
        else
        {
            // Enables/sets player stuff and disables NPC stuff
            go.transform.parent = FindObjectOfType <AdvancedHivemind>().transform;
            go.tag = "Player";
            rnpc.SetAIBehaviourActive(false);
            rnpc.enabled = false;
            rpi.enabled  = true;
            ci.enabled   = true;
        }

        //go.AddComponent<Entity>().CopyStats(entity);
        //allCharacters[allCharacters.IndexOf(entity)] = go.GetComponent<Entity>();
        //charactersOnLevel.Add(go.GetComponent<Entity>());

        //Debug.Log("Entity: " + go.GetComponent<Entity>().character.characterName);

        //if (go.GetComponent<Entity>().isInfected) infectedCharacters.Add(go.GetComponent<Entity>());

        //go.AddComponent<Entity>().character = entity.character;
        //Debug.Log(go.GetComponent<Entity>().character.characterName);

        Entity e = go.GetComponent <Entity>();

        //e.character = entity.character;
        CopyEntities(ref e, entity);
        Debug.Log(allCharacters[allCharacters.IndexOf(entity)]);

        allCharacters[allCharacters.IndexOf(entity)] = go.GetComponent <Entity>();
        charactersOnLevel.Add(go.GetComponent <Entity>());
        if (go.GetComponent <Entity>().isInfected)
        {
            infectedCharacters.Add(go.GetComponent <Entity>());
        }

        // Hides comment box
        go.transform.GetComponentInChildren <RandomComment>().transform.parent.gameObject.SetActive(false);

        return(go);
    }
Ejemplo n.º 28
0
 private void Start()
 {
     characterInteraction = GetComponentInParent <CharacterInteraction>();
     interactionCanvas    = GameObject.Find("InteractionCanvas").GetComponent <Canvas>();
 }
Ejemplo n.º 29
0
 public override void Interact(CharacterInteraction tar)
 {
     base.Interact(tar);
     IsConnected = false;
     connectedCable.SetSelectedEnd(this);
 }
Ejemplo n.º 30
0
 // Use this for initialization
 protected virtual void Start()
 {
     game_controller       = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>();
     character_interaction = GameObject.FindGameObjectWithTag("Player").GetComponent <CharacterInteraction>();
 }
Ejemplo n.º 31
0
 public void OnDefocus(CharacterInteraction focuser)
 {
     UpgradeManager.Instance.HideUpgradeWindow();
     Debug.Log("Defocused Upgrade");
 }