コード例 #1
0
    public override void Initialise()
    {
        myType       = behaviourType.updateSuspects;
        myController = this.gameObject.GetComponent <NPCController> ();

        if (myController.memory.objectThatMadeMeSuspisious == null)
        {
        }
        else
        {
            if (myController.memory.objectThatMadeMeSuspisious.tag == "NPC")
            {
                NPCController npc = myController.memory.objectThatMadeMeSuspisious.GetComponent <NPCController> ();
                if (myController.npcB.freindlyIDs.Contains(npc.npcB.myID) == true || myController.npcB.myID != npc.npcB.myID)
                {
                    myController.npcB.suspisious = false;
                    ////////Debug.LogError ("NPC " + this.gameObject.name + " wanted to set alert on freindly npc " + myController.memory.objectThatMadeMeSuspisious);

                    myController.memory.objectThatMadeMeSuspisious = null;
                    Destroy(this);
                }
            }
        }
        radioMessageOnStart();
        myController.pf.getPath(this.gameObject, LevelController.me.raiseAlarmLoc.gameObject);
        isInitialised = true;
    }
コード例 #2
0
    private Vector3 Cohesion()
    {
        //error checking: if not find the script attached on Phase Manager
        if (GameObject.Find("PhaseManager") == null)
        {
            return(new Vector3(0f, 0f, 0f));
        }
        else if (GameObject.Find("PhaseManager").GetComponent <FieldMapManager>() == null)
        {
            return(new Vector3(0f, 0f, 0f));
        }
        //get all npcs in the scene
        List <GameObject> allNPCs = GameObject.Find("PhaseManager").GetComponent <FieldMapManager>().AllNPCs();

        Vector3 averagePos = new Vector3();
        int     NPCCount   = 0;

        foreach (GameObject NPC in allNPCs)
        {
            //make sure NPC only follows the NPC with same tag
            if (NPC.tag == this.tag && NPC != this)
            {
                //calculate the total position
                NPCController nc = NPC.GetComponent <NPCController>();
                averagePos += nc.position;
                NPCCount   += 1;
            }
        }
        //calculate the average position
        averagePos /= NPCCount;
        return(Seek(averagePos));
    }
コード例 #3
0
ファイル: Window.cs プロジェクト: Galux27/OneManBandit
    public void smashWindow()
    {
        smashed         = true;
        sr.sprite       = smashedSprite;
        sr.color        = new Color(1, 1, 1, 1);
        sr.sortingOrder = 1;
        //if (counter == openAnimation.Length - 1) {
        this.gameObject.GetComponent <Collider2D> ().enabled = false;
        //}
        this.gameObject.GetComponent <AudioController> ().playSound(SFXDatabase.me.smashGlass);

        foreach (GameObject g in NPCManager.me.npcsInWorld)
        {
            if (g == null)
            {
                continue;
            }
            NPCController npc = g.GetComponent <NPCController> ();
            npc.setHearedGunshot(this.transform.position, 14.0f);
        }
        PoliceController.me.setNoiseHeard(this.transform.position, 14.0f);


        PlayerAction pa = this.gameObject.GetComponent <PlayerAction> ();

        Destroy(pa);
        HighlightObjectWithPlayerActions h = this.gameObject.GetComponent <HighlightObjectWithPlayerActions> ();

        Destroy(h);
        SpriteOutline s = this.gameObject.GetComponent <SpriteOutline> ();

        Destroy(s);
    }
コード例 #4
0
    public void AddFollower(NPCController follower)
    {
        Followers.Add(follower);
        follower.commander = this;

        CommandFollowerInvade(follower);
    }
コード例 #5
0
ファイル: Trap.cs プロジェクト: bmjoy/knights-of-life
    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            Debug.Log(transform.name + " not focused by: " + other.gameObject.name);

            interactionSign.enabled = false;

            PlayerControllerCC player = other.gameObject.GetComponent <PlayerControllerCC>();
            if (player != null)
            {
                player.onInteracting -= Interact;
            }
        }

        if (other.gameObject.CompareTag("Death"))
        {
            DeathController dController = other.GetComponent <DeathController>();
            if (dController != null)
            {
                dController.onInteracting -= DeathInteract;
            }
        }

        if (other.gameObject.CompareTag("NPC"))
        {
            NPCController npcController = other.GetComponent <NPCController>();
            if (npcController != null)
            {
                npcController.onInteracting -= VictimInteract;
            }
        }
    }
コード例 #6
0
    private void Spawn()
    {
        if (spawnedEnemy == null)
        {
            spawnedEnemy = Instantiate(enemyPrefab, transform.position, Quaternion.identity);
            spawnedEnemy.GetComponent <CharacterStats>().OnDead += StartSpawnCoroutine;

            if (patrollingEnemy)
            {
                Destroy(spawnedEnemy.GetComponent <SearchingState>());
                NPCController npcController = spawnedEnemy.GetComponent <NPCController>();

                float rand = Random.Range(minPatrolWaitTime, maxPatrolWaitTime);
                npcController.SetPatrolWaitTime(rand);
                npcController.SetPatrolPath(patrolPath);

                spawnedEnemy.AddComponent <PatrolState>();
                npcController.UpdateStateComponents();
            }
        }
        else
        {
            StartCoroutine(WaitForSpawn());
        }
    }
コード例 #7
0
ファイル: CombatController.cs プロジェクト: Khashan/RpgSchool
 public void FriendlyAttack(int aAttackingPosition, int aAttackedPosition)
 {
     //Sets the values of the ennemy attacked. includes setting the posistions and getting its animator and renderer
     m_IsFirstTurn           = false;
     m_CurrentEnnemyAttacked = aAttackedPosition + 4;
     m_CurrentFriendlyStats  = m_FriendlyList[aAttackingPosition].GetComponent <NPCController>();
     m_CurrentEnnemyStats    = m_EnnemyList[aAttackedPosition].GetComponent <NPCController>();
     m_CurrentEnnemyGO       = m_EnnemyList[aAttackedPosition];
     m_CurrentFriendlyGO     = m_FriendlyList[aAttackingPosition];
     m_CurentIdle            = m_FriendlyIdlePositions[aAttackingPosition];
     m_CurrentDestination    = m_FriendlyAttackingPositions[aAttackedPosition];
     m_CurrentFriendlyAnim   = m_CurrentFriendlyGO.GetComponent <Animator>();
     m_CurrentEnnemyAnim     = m_CurrentEnnemyGO.GetComponent <Animator>();
     m_CurrentRend           = m_CurrentFriendlyGO.GetComponent <SpriteRenderer>();
     if (m_CurrentFriendlyStats != null && m_CurrentEnnemyStats != null && m_CurrentEnnemyGO != null && m_CurrentFriendlyGO != null)
     {
         m_IsFriendlyAttacking = true;
     }
     m_oldorderinlayer          = m_CurrentRend.sortingOrder;
     m_CurrentRend.sortingOrder = 12;
     if (!m_IsFriendlyAttacking)
     {
         Debug.LogError("STATS WERE NOT SET CORRECTLY");
     }
 }
コード例 #8
0
    private void Assign(StartGameEvent e)
    {
        // Handle event here
        for (int i = 0; i < _players.Length; i++)
        {
            NPCController    npcController    = _players[i].GetComponent <NPCController>();
            GhostController  ghostController  = _players[i].GetComponent <GhostController>();
            HunterController hunterController = _players[i].GetComponent <HunterController>();

            if (e.gameMode == GameMode.Practice)
            {
                hunterController.AlwaysRevealed = true;
                ghostController.AlwaysRevealed  = true;
            }

            npcController.enabled    = true;
            hunterController.enabled = false;
            ghostController.enabled  = false;
            int minimumFurnitureCount = Mathf.Max(0, RoomManager.g.RoomCount - 1);
            int maximumFurnitureCount = RoomManager.g.RoomCount;
            npcController.InitFurniturePattern(RoomManager.g.RandomFurnitureList(Random.Range(minimumFurnitureCount, maximumFurnitureCount)));
        }

        int hunterIndex = Random.Range(0, _players.Length);
        int ghostIndex  = Random.Range(0, _players.Length);

        if (ghostIndex == hunterIndex)
        {
            ghostIndex = (hunterIndex + 1) % _players.Length;
        }
        _players[hunterIndex].GetComponent <HunterController>().enabled = true;
        _players[ghostIndex].GetComponent <GhostController>().enabled   = true;
    }
コード例 #9
0
 // Use this for initialization
 void Start()
 {
     myController      = this.GetComponent <NPCController> ();
     useMultiThreading = true;
     pathSmoothing     = false;
     StartCoroutine("checkIfStuck");
 }
コード例 #10
0
ファイル: CombatController.cs プロジェクト: Khashan/RpgSchool
    private int RandomizeEnnemyAttack()
    {
        //randomizes the attack of the ennemy according to how many
        //alive players are left
        for (int i = 0; i < 3; i++)
        {
            NPCController tempfriendly = m_FriendlyList[i].GetComponent <NPCController>();
            if (!tempfriendly.isDead)
            {
                m_AliveFriendlies++;
                m_PossibleEnnemyAttacks.Add(i + 1);
            }
        }
        if (m_AliveFriendlies > 0)
        {
            int finalennemyattack;
            if (m_AliveFriendlies > 1)
            {
                int randennemyattack = (int)UnityEngine.Random.Range(0, m_PossibleEnnemyAttacks.Count);
                finalennemyattack = m_PossibleEnnemyAttacks[randennemyattack];
                m_PossibleEnnemyAttacks.Clear();
                return(finalennemyattack);
            }
            else
            {
                finalennemyattack = m_PossibleEnnemyAttacks[0];
                m_PossibleEnnemyAttacks.Clear();
                return(finalennemyattack);
            }
        }

        m_PossibleEnnemyAttacks.Clear();
        Debug.LogError("ALL FRIENDLIES ARE DEAD");
        return(0);
    }
コード例 #11
0
 protected override void OnAwake()
 {
     base.OnAwake();
     manager       = GameObject.FindObjectOfType <CombatManager>();
     renderer      = this.GetComponent <SpriteRenderer>();
     npcController = this.GetComponent <NPCController>();
 }
コード例 #12
0
 // Use this for initialization
 void Start()
 {
     enemyInfoAgent  = GetComponent <EnemyInfoAgent>();
     enemyController = GetComponent <NPCController>();
     enemyAnima      = enemyController.m_Animator;
     if (frontAtkTrigger)
     {
         frontAtkTrigger.enabled        = false;
         frontAtkTrigger.gameObject.tag = "EnemyWeapon";
         if (!frontAtkTrigger.isTrigger)
         {
             frontAtkTrigger.isTrigger = true;
         }
     }
     if (backAtkTrigger)
     {
         backAtkTrigger.enabled        = false;
         backAtkTrigger.gameObject.tag = "EnemyWeapon";
         if (!backAtkTrigger.isTrigger)
         {
             backAtkTrigger.isTrigger = true;
         }
     }
     bodyCollider = enemyController.GetComponent <Collider>();
     behaviorTree = GetComponent <BehaviorDesigner.Runtime.BehaviorTree>();
 }
コード例 #13
0
    // Define Output
    override public Steering Output(Kinematic lead)
    {
        // Calculate prediction scalar based on current speed and target distance
        float         shortestTime    = Mathf.Infinity;
        NPCController firstTarget     = null;
        float         firstSeparation = 0;
        float         firstDistance   = 0;
        Vector2       firstPosition   = Vector2.zero;
        Vector2       firstVelocity   = Vector2.zero;

        foreach (NPCController target in targets)
        {
            // Calculate the time to collision
            Vector2 position        = target.data.position - player.data.position;
            Vector2 velocity        = target.data.velocity - player.data.velocity;
            float   timeToCollision = (Vector2.Dot(position, velocity) / (velocity.magnitude * velocity.magnitude));

            // Check if the collision will happen
            float distance   = position.magnitude;
            float separation = distance - velocity.magnitude * shortestTime;
            if (separation > 2 * radius)
            {
                continue;
            }

            // Check if it is the shortest
            if (timeToCollision > 0 && timeToCollision < shortestTime)
            {
                // Store the time, target and other data
                shortestTime    = timeToCollision;
                firstTarget     = target;
                firstSeparation = separation;
                firstDistance   = distance;
                firstPosition   = position;
                firstVelocity   = velocity;
            }
        }

        // Calculate the steering
        if (firstTarget == null)
        {
            return(new Steering());
        }

        // If we’re going to hit exactly, or if we’re already colliding, then do the steering based on current position.
        Vector2 relativePos = Vector2.zero;

        if (firstSeparation <= 0 || firstDistance < 2 * radius)
        {
            relativePos = firstTarget.data.position - player.data.position;
        }
        else
        {
            // Otherwise calculate the future relative position
            relativePos = firstPosition + firstVelocity * shortestTime;
        }

        // Return the steering
        return(new Steering(Vector2.ClampMagnitude(relativePos, player.maxAccelerationL), 0));
    }
コード例 #14
0
    private void Shoot()
    {
        int numberOfBullets = AC.GlobalVariables.GetIntegerValue (5);
        if (numberOfBullets > 0 && AC.GlobalVariables.GetBooleanValue (52)) {
            this.renderer.sprite = shoot;
            AC.GlobalVariables.SetIntegerValue (5, numberOfBullets - 1);
            TargetMovement t = GameObject.FindObjectOfType<TargetMovement> ();
            Collider2D hitCollider = Physics2D.OverlapCircle (t.transform.position, t.GetComponent<CircleCollider2D> ().radius, 1 << LayerMask.NameToLayer ("Body Part"));

            //if (hitCollider == null || !enemy.IsStanding ()) {
            if (hitCollider == null) {
                //GameObject.Find ("Missed").GetComponent <AC.Cutscene> ().Interact ();
                MonoBehaviour.print ("miss");
            } else {
                BodyPart part = hitCollider.gameObject.GetComponent<BodyPart> ();
                enemy = part.GetComponentInParent<NPCController> ();
                enemy.GetBarkTrigger ().TryBark (this.transform);
                //GameObject.Find ("BeltHit").GetComponent <AC.Cutscene> ().Interact ();
                //Debug.Log (part.gameObject.name + " shot. You did " + part.damage + " damage");
                Shootable npc = hitCollider.gameObject.GetComponentInParent<Shootable> ();
                npc.DecreaseHP (part.damage);
                //npc.GetComponent<NPCController> ().ForceToggle ();
            }

        } else {
            Destroy (FindObjectOfType<TargetMovement> ().gameObject);
            AC.GlobalVariables.SetBooleanValue (52, false);
        }
    }
コード例 #15
0
    /// <summary>
    /// Начать диалог
    /// </summary>
    public void BeginDialog(NPCController _npc, Dialog dialog)
    {
        npc                 = _npc;
        currentDialog       = dialog;
        currentDialog.stage = 0;

        CurrentSpeech = dialog.speeches[0];

        canvas.enabled = true;

        HeroController hControl = hero.GetComponent <HeroController>();

        hControl.SetImmobile(true);

        //Повернуть персонажей друг к другу
        prevScale1 = hero.localScale.x;
        prevScale2 = npc.transform.localScale.x;
        if (hero.localScale.x * (npc.transform.position - hero.position).x < 0f)
        {
            hero.localScale += new Vector3(-2f * prevScale1, 0f);
        }
        if (npc.transform.localScale.x * (npc.transform.position - hero.position).x < 0f)
        {
            npc.transform.localScale += new Vector3(-2f * prevScale2, 0f);
        }

        if (currentDialog.pause)
        {
            SpecialFunctions.PauseGame();
        }
        noInput = 0;
    }
コード例 #16
0
    private void fireEx()
    {
        RaycastHit2D[] hits;
        if (facingRight)
        {
            hits = Physics2D.RaycastAll(rayRight.position, Vector2.right, .3f);
        }
        else
        {
            hits = Physics2D.RaycastAll(rayLeft.position, Vector2.left, .3f);
        }

        foreach (RaycastHit2D H in hits)
        {
            print("runs");
            //14th layer is the layer of Npcs so this detects if its an Npc
            if (H.collider.gameObject.layer == 14)
            {
                print("la");
                NPCController temp = H.collider.gameObject.GetComponent <NPCController>();
                if (temp.isOnFire())
                {
                    //put the fire out
                    temp.putOutFire();
                    print("yeet");
                }
            }
        }
    }
コード例 #17
0
 private void Start()
 {
     startingLocation = transform.position;
     initialRotation  = transform.rotation;
     agent            = GetComponent <NavMeshAgent>();
     npcController    = GetComponent <NPCController>();
 }
コード例 #18
0
    public List <NPCController> prepareNeighourhood()
    {
        List <NPCController> nh = new List <NPCController>();

        foreach (NPCController boid in boids)
        {
            if (boid.k.Equals(character))
            {
                continue;
            }
            if ((boid.k.position - character.position).magnitude < 10f)
            {
                nh.Add(boid);

                //Debug.DrawLine(character.position, boid.k.position, Color.blue);
            }
        }
        if (nh.Count != 0)
        {
            lastNeighbor = nh[0];
        }



        return(nh);
    }
コード例 #19
0
    // Define Output
    override public Steering Output(Kinematic lead)
    {
        // Define variables
        Vector2       orientation = new Vector2(Mathf.Sin(player.data.rotation), Mathf.Cos(player.data.rotation));
        NPCController nearest     = null;

        // Obtain the data for nearest boid and calculate separation velocity
        foreach (NPCController target in targets)
        {
            if (Vector2.Dot(orientation, (target.data.position - player.data.position)) > threshold)
            {
                if (nearest == null || Vector2.Distance(player.data.position, target.data.position) < Vector2.Distance(player.data.position, nearest.data.position))
                {
                    nearest = target;
                }
            }
        }

        // Return no change if no nearby boid found
        if (nearest == null)
        {
            return(new Steering());
        }

        // Otherwise, calculate separate
        return(base.Output(nearest.data));
    }
コード例 #20
0
    public override void Initialise()
    {
        myType       = behaviourType.arrestTarget;
        myController = this.gameObject.GetComponent <NPCController> ();
        pwc          = target.GetComponent <PersonWeaponController> ();
        myController.detect.target = target;
        targetStartLoc             = target.transform.position;

        if (myController.memory.objectThatMadeMeSuspisious == null)
        {
        }
        else
        {
            if (myController.memory.objectThatMadeMeSuspisious.tag == "NPC")
            {
                NPCController npc = myController.memory.objectThatMadeMeSuspisious.GetComponent <NPCController> ();
                if (myController.npcB.freindlyIDs.Contains(npc.npcB.myID) == true || myController.npcB.myID != npc.npcB.myID)
                {
                    myController.npcB.suspisious = false;
                    ////////Debug.LogError ("NPC " + this.gameObject.name + " wanted to set alert on freindly npc " + myController.memory.objectThatMadeMeSuspisious);

                    myController.memory.objectThatMadeMeSuspisious = null;
                    Destroy(this);
                }
            }
        }
        radioMessageOnStart();
        isInitialised = true;
    }
コード例 #21
0
ファイル: ChaseState.cs プロジェクト: rob893/RPG-Game-Scripts
 private void Start()
 {
     npcController = GetComponent <NPCController>();
     npcController.TargetChanged += ChangeTarget;
     agent    = GetComponent <NavMeshAgent>();
     animator = GetComponent <CharacterAnimator>();
 }
コード例 #22
0
    private void LoadRandomQAToGeneral()
    {
        const int mainQuestionCount = 13;

        int[] randomArray = new int[mainQuestionCount];
        int   length      = 0;
        int   randomIndex;

        //Get SIX (static) random different QA set from the mainQuestionSource
        for (int i = 0; i < 6; i++)
        {
            //While the random index is exists in the random index array
            do
            {
                //Keep random the index
                randomIndex = Random.Range(0, mainQuestionCount);
            } while (IsExists(randomArray, randomIndex));


            //Add the new randomIndex to the random index array
            randomArray[length++] = randomIndex;

            //Add the QASetSource to the randomMainQASet list
            randomMainQASet.Add(mainQuestionsSource[randomIndex]);
        }

        // Add the NPCController's Script component to the general GameObject
        npc = general.AddComponent <NPCController>();

        //Change the settings of this component by using the AddQA function
        npc.AddQA(randomMainQASet);
    }
コード例 #23
0
ファイル: CRController.cs プロジェクト: silantzis/quest
    public void deaggro(NPCController npc)
    {
        _aggroList.Remove(npc);

        if (_indirectAggroList.Contains(npc))
            _indirectAggroList.Add(npc);
    }
コード例 #24
0
    private void EnterMapStateOne()
    {
        //destroy all of the NPCs in the scene
        Debug.Log("map state one");
        Debug.Log(spawnedNPCs.Count);
        for (int i = 0; i < spawnedNPCs.Count; i++)
        {
            Debug.Log(spawnedNPCs.Count + "<count i> " + i);
            if (spawnedNPCs[i] == null)
            {
                continue;
            }
            Destroy(spawnedNPCs[i]);
        }
        spawnedNPCs.Clear();

        GameObject character = SpawnItem(spawner1, HunterPrefab, null, SpawnText1, 0);
        GameObject wolf      = SpawnItem(spawner2, WolfPrefab, null, SpawnText1, 0);

        spawnedNPCs.Add(character);
        spawnedNPCs.Add(wolf);

        NPCController charNPCcontroller = character.GetComponent <NPCController>();
        NPCController wolfNPCcontroller = wolf.GetComponent <NPCController>();

        charNPCcontroller.NewTarget(wolfNPCcontroller);
        wolfNPCcontroller.NewTarget(charNPCcontroller);


        charNPCcontroller.mapState = 1;
        wolfNPCcontroller.mapState = 2;
    }
コード例 #25
0
    protected bool ShouldCastRangeHealingPredefine(NPCController caster, List <Transform> TargetsInVision, BaseSkill skillSetting)
    {
        //技能總治療量
        float healingMount = 0;

        if (skillSetting is BuffSkill)
        {
            foreach (Buff buff in (skillSetting as BuffSkill).buffs)
            {
                if (buff is ConsumedStatusBuff)
                {
                    healingMount += (buff as ConsumedStatusBuff).TotalMount((skillSetting as BuffSkill).buffTime);
                }
            }
        }
        healingMount += caster.status.GetSecondaryAttrubute(SecondaryAttributeName.MagicalDamage).AdjustedValue *skillSetting.AdjustedDamage;
        foreach (Transform target in TargetsInVision)
        {
            if (target.GetComponent <BaseCharacterBehavior>().status.GetConsumedAttrubute(ConsumedAttributeName.Health).LossValue > healingMount / 2)
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #26
0
 // Use this for initialization
 void Start()
 {
     if (!nPC)
     {
         nPC = this.transform.gameObject.GetComponentInParent <NPCController>();
     }
 }
コード例 #27
0
 void OnCollisionEnter2D(Collision2D col)
 {
     if (playerInCar == true && rb.velocity.magnitude > 1)
     {
         //Debug.Log ("CAR COLLIDED WITH " + col.gameObject.name);
         if (col.gameObject.GetComponent <NPCController> () == true)
         {
             NPCController npc = col.gameObject.GetComponent <NPCController> ();
             npc.knockOutNPC();
             //Debug.Log ("Dealt " + Mathf.RoundToInt (100 * rb.velocity.magnitude).ToString () + " Damage to NPC");
             npc.myHealth.dealDamage(Mathf.RoundToInt(100 * rb.velocity.magnitude), true);
         }
         else if (col.gameObject.GetComponent <DoorScript> () == true)
         {
             DoorScript ds = col.gameObject.GetComponent <DoorScript> ();
             ds.largeImpactOnDoor(100);
         }
         else if (col.gameObject.transform.parent != null && col.gameObject.transform.parent.GetComponent <WindowNew> () == true)
         {
             WindowNew wn = col.gameObject.transform.parent.GetComponent <WindowNew> ();
             wn.destroyWindow();
         }
         dealDamage(100);
     }
 }
コード例 #28
0
ファイル: Pets.cs プロジェクト: gragonvlad/umod-plugin-search
        private void OnPlayerInit(BasePlayer player)
        {
            if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
            {
                timer.Once(2, () => OnPlayerInit(player));
                return;
            }
            PetData info;

            if (!npcSaveList.TryGetValue(player.userID, out info) || !info.NeedToSpawn)
            {
                return;
            }

            Puts("Loading pet...");
            BaseEntity pet = InstantiateEntity(StringPool.Get(info.prefabID), new Vector3(info.x, info.y, info.z), new Quaternion());

            if (pet == null)
            {
                return;
            }

            NPCController controller = player.gameObject.AddComponent <NPCController>();

            pet.enableSaving = false;
            pet.Spawn();

            controller.npcAi       = pet.gameObject.AddComponent <NpcAI>();
            controller.npcAi.owner = controller;
            controller.npcAi.inventory.Load(ProtoBuf.ItemContainer.Deserialize(info.inventory));
            info.NeedToSpawn = false;
        }
コード例 #29
0
    private float FlockingAlgA()
    {
        float avgAng    = 0;
        int   collCount = 0;

        foreach (Collider coll in cylnCheck.CollidersClose)
        {
            NPCController collNPC = coll.gameObject.GetComponent <NPCController>();
            if (collNPC && collNPC.team == agent.team)
            {
                avgAng += coll.transform.rotation.eulerAngles.y;
                collCount++;
            }
        }
        avgAng /= collCount;
        while (avgAng > 180)
        {
            avgAng -= 360;
        }
        while (avgAng < -180)
        {
            avgAng += 360;
        }
        return(Align(avgAng));
    }
コード例 #30
0
 private void OnTriggerEnter2D(Collider2D coll)
 {
     if (coll.gameObject.tag == "NPC")
     {
         atNPC = true;
         NPC   = coll.gameObject.GetComponent <NPCController>();
     }
     else if (coll.gameObject.tag == "Enemy")
     {
         if (isAttacking)
         {
             coll.gameObject.GetComponent <DogController>().Kill();
             Physics2D.IgnoreCollision(coll, GetComponent <BoxCollider2D>());
         }
         else
         {
             if (coll.gameObject.GetComponent <DogController>().isDead)
             {
                 Physics2D.IgnoreCollision(coll, GetComponent <BoxCollider2D>());
             }
             else
             {
                 GetComponent <PlayerHealth>().TakeDamage(0.5f);
             }
         }
     }
 }
コード例 #31
0
    private void Start()
    {
        patrolPath = GetComponentInChildren <WaypointContainer>();

        if (GetComponentInChildren <CharacterStats>())
        {
            CharacterStats enemy = GetComponentInChildren <CharacterStats>();
            enemy.OnDead += StartSpawnCoroutine;
            spawnedEnemy  = enemy.gameObject;

            if (patrollingEnemy)
            {
                Destroy(spawnedEnemy.GetComponent <SearchingState>());
                NPCController npcController = spawnedEnemy.GetComponent <NPCController>();

                float rand = Random.Range(minPatrolWaitTime, maxPatrolWaitTime);
                npcController.SetPatrolWaitTime(rand);
                npcController.SetPatrolPath(patrolPath);

                spawnedEnemy.AddComponent <PatrolState>();
                npcController.UpdateStateComponents();
            }

            spawnedEnemy.transform.parent = null;
        }
        else
        {
            Spawn();
        }
    }
コード例 #32
0
    public void setBoidVelocity()
    {
        SteeringOutput steering;

        steering.linear = Vector3.zero;

        steering.angular = 0f;

        Vector3 returnVel = Vector3.zero;

        for (int i = 0; i < boidParent.transform.childCount; i++)
        {
            Transform     currentBoid    = boidParent.transform.GetChild(i);
            NPCController currentBoidNPC = currentBoid.GetComponent <NPCController>();
            if (!currentBoidNPC)
            {
                Debug.Log("No NPC Controller attatched to Boid " + currentBoid.gameObject.name);
                return;
            }
            if (currentBoid == transform)
            {
                continue;
            }
            if ((transform.position - currentBoid.position).magnitude < 10f)
            {
                returnVel += currentBoidNPC.so.linear;
            }
        }
    }
コード例 #33
0
 public WaitingState(GameObject player, GameObject npc)
 {
     base.player = player;
     base.npc = npc;
     playerScript = player.GetComponent<PlayerScene2>();
     npcScript = npc.GetComponent<NPCController>();
     stateID = StateID.WaitingStateID;
 }
コード例 #34
0
    public void DisplayPhraseSelector(string conflictPhrase = "This is a conflict we're having", NPCController npc = null)
    {
        PhraseSelector.SetActive(true);

        PhraseSelector controller = this.PhraseSelector.GetComponent<PhraseSelector>();
        controller.SetConflictPhrase(conflictPhrase);
        controller.SpawnPhrases(PhraseCollector.Instance.GetAllCollectedPhrases());
        controller.SetNPC(npc);
    }
コード例 #35
0
ファイル: Bland.cs プロジェクト: MikevanLoe/EggshellVR
    public Bland(NPCController c)
        : base(c)
    {
        _voiceClips.Add(_gameController.GetClip ("bezoeker_01"));
        _voiceClips.Add(_gameController.GetClip ("bezoeker_02"));
        _voiceClips.Add(_gameController.GetClip ("bezoeker_03"));
        _voiceClips.Add(_gameController.GetClip ("bezoeker_04"));

        _demand = Random.Range(1, 10);
    }
コード例 #36
0
 void Start()
 {
     objPlayer = GameObject.FindGameObjectWithTag("Player");
     // enable/disable NPCController script if attacking
     npc = gameObject.GetComponent<NPCController>();
     weapon = gameObject.GetComponent<Done_WeaponController>();
     flockControl = gameObject.transform.parent.GetComponent<FlockController>();
     flock = gameObject.transform.parent.GetComponent<Flock>();
     //	Debug.Log(npc.GetPlayerTransform().position + "player place");
 }
コード例 #37
0
ファイル: Guard.cs プロジェクト: MikevanLoe/EggshellVR
    public Guard(NPCController c)
        : base(c)
    {
        _voiceClips.Add(_gameController.GetClip ("speler_01"));
        _voiceClips.Add(_gameController.GetClip ("guard_01"));

        var Player = GameObject.FindGameObjectWithTag ("Player");
        _playerAudioSource = Player.GetComponent<AudioSource> ();
        MonoBehaviour.Destroy (_client.gameObject, DestroyTime);

        _demand = Mathf.Infinity;
    }
コード例 #38
0
ファイル: HappyFisher.cs プロジェクト: MikevanLoe/EggshellVR
    public HappyFisher(NPCController c)
        : base(c)
    {
        _voiceClips.Add(_gameController.GetClip ("visser_01"));
        _voiceClips.Add(_gameController.GetClip ("visser_02"));
        _voiceClips.Add(_gameController.GetClip ("visser_03"));
        _voiceClips.Add(_gameController.GetClip ("visser_04"));
        _voiceClips.Add(_gameController.GetClip ("visser_05"));
        _voiceClips.Add(_gameController.GetClip ("visser_06"));

        _demand = 50;
    }
コード例 #39
0
ファイル: Personality.cs プロジェクト: MikevanLoe/EggshellVR
 public Personality(NPCController c)
 {
     _client = c;
     _audioSource = _client.GetComponent<AudioSource> ();
     _voiceClips = new List<AudioClip>();
     if (_audioSource == null)
         throw new UnityException ("NPC has no audio source attached.");
     var gameObject = GameObject.FindGameObjectWithTag ("GameController");
     if (gameObject == null)
         throw new UnityException ("No game controller found in scene.");
     _gameController = gameObject.GetComponent<GameController> ();
 }
コード例 #40
0
ファイル: Smith.cs プロジェクト: MikevanLoe/EggshellVR
    public Smith(NPCController c)
        : base(c)
    {
        _voiceClips.Add(_gameController.GetClip ("smid_01"));
        _voiceClips.Add(_gameController.GetClip ("smid_02"));
        _voiceClips.Add(_gameController.GetClip ("smid_03"));

        var Player = GameObject.FindGameObjectWithTag ("Player");
        _playerController = Player.GetComponent<PlayerController> ();

        _demand = 40;
    }
コード例 #41
0
 void Start()
 {
     GameObject sectorController = GameObject.Find("SectorController");
     if (sectorController != null)
     {
         sc = sectorController.GetComponent<SectorController>();
         nc = sectorController.GetComponent<NPCController>();
     }
     else
     {
         throw new System.Exception("Cannot find SectorController. Is it present and named 'SectorController'?");
     }
 }
コード例 #42
0
    public GameObject SpawnNPC(SpawnPoint spawnPoint,
	                      Emotion emotion,
	                      string phrase,
	                      NPCController.CollidedWithPlayerAction collidedListener)
    {
        GameObject npcObject = spawnNPC(spawnPoint);
        NPCController npc = npcObject.GetComponent<NPCController>();
        npc.Emotion = emotion;
        if (emotion == Emotion.Mad) {
            npc.SetConflictPhrase(phrase);
        } else {
            npc.Phrase = phrase;
        }
        npc.OnCollidedWithPlayer += collidedListener;
        return npcObject;
    }
コード例 #43
0
ファイル: GameController.cs プロジェクト: JulianVallee/RTS
	void Awake () 
	{		
		// Singleton pattern
		if (instance == null) 
		{
			// Gameinstance related stuff here
			/************************************/
			// For static reference
			instance = this;

			// PaycastMask for ignoring the buildings
			Layer = 0;
			raycastIgnoreMask = 1 << Layer;
			raycastIgnoreMask = ~raycastIgnoreMask;

			// Instantiate all controllers
			gridFieldController = new GridFieldController();
			treeGroupController = new TreeGroupController();
			buildingController = new BuildingController();
			npcController = new NPCController();

			// Nothing opened, nothing selected!
			selectedBuilding = 123456;
			selectedNPC = 123456;
			isSelected = false;
			isBuilding = false;


			// Wallet related stuff here
			/************************************/
			// Number of wallets are determined by the number of Player Names
			// How much starting cash is given to the constructor
			walletController = new WalletController(2000);
		}
		else if(instance != this)
		{
			// Singleton pattern - destroy the new one if you want to make another GameController
			Destroy(gameObject);
		}
	}
コード例 #44
0
 void Start()
 {
     renderer = this.GetComponent<SpriteRenderer> ();
     if (renderer == null) {
         this.GetComponentInChildren<SpriteRenderer> ();
     }
     enemy = GameObject.FindObjectOfType<NPCController> ();
     barkTrigger = this.GetComponent<BarkTrigger> ();
     isStanding = true;
     player = GetComponent<Player> ();
     if (player == null) {
         player = GetComponentInParent<Player> ();
     }
     if (player == null) {
         player = GetComponentInChildren<Player> ();
     }
     if (player != null) {
         speed = player.walkSpeedScale;
         animator = player.GetComponent<Animator> ();
     } else {
         speed = 2f;
     }
 }
コード例 #45
0
 void callNPCEncounterEvent(Emotion emotion, string phrase, NPCController npc)
 {
     if (OnNPCEncounter != null) {
         OnNPCEncounter(emotion, phrase, npc);
     }
 }
コード例 #46
0
    void OnEnable()
    {
        script = target as NPCController;
        list = new ReorderableList(serializedObject, serializedObject.FindProperty("dialogs"), true, true, true, true);

        list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
            if (!list.serializedProperty.isExpanded) return;

            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            rect.x += 15;
            rect.width -= 15;
            rect.height = EditorGUI.GetPropertyHeight(element) + 2;
            EditorGUI.PropertyField(rect, element);
        };

        list.elementHeightCallback = (int index) => {
            if (!list.serializedProperty.isExpanded) return 0;

            var element = list.serializedProperty.GetArrayElementAtIndex(index);
            float h = EditorGUI.GetPropertyHeight(element) + 6;

            // If it's not the last one, but it's the last playOnce...
            if (element.FindPropertyRelative("messages").isExpanded && ShowLastPlayOnceStuff(index))
                h += 20;

            return h;
        };

        list.drawHeaderCallback = (Rect rect) => {
            //EditorGUI.LabelField(rect, list.serializedProperty.displayName);
            //EditorGUI.LabelField(rect, "Conversations");
            EditorGUI.indentLevel++;
            list.serializedProperty.isExpanded = EditorGUI.Foldout(rect, list.serializedProperty.isExpanded, "Conversations");
            EditorGUI.indentLevel--;

            list.draggable =
            list.displayAdd =
            list.displayRemove = list.serializedProperty.isExpanded;
        };

        list.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
            if (!list.serializedProperty.isExpanded) return;
            if (index < 0) return;

            bool playOnce = list.serializedProperty.GetArrayElementAtIndex(index).FindPropertyRelative("playOnce").boolValue;

            rect.y -= 2;
            rect.x += 1;
            rect.width -= 2;
            rect.height = list.elementHeightCallback(index);
            EditorGUI.DrawRect(rect, isFocused
                ? (playOnce ? new Color(0.2f, 0.5f, 0.2f, 0.2f) : new Color(0.2f, 0.2f, 0.2f, 0.2f))
                : (playOnce ? new Color(0, 1, 0, 0.1f) : Color.clear));

            if (ShowLastPlayOnceStuff(index)) {
                var bot = new Rect(rect.x, rect.yMax-1, rect.width, 1);
                EditorGUI.DrawRect(bot, new Color(0, 0.5f, 0, 0.5f));
            }
        };

        list.onAddCallback = (ReorderableList l) => {
            int index = l.count;
            l.serializedProperty.InsertArrayElementAtIndex(index);
            var sub = l.serializedProperty.GetArrayElementAtIndex(index);

            sub.FindPropertyRelative("playOnce").boolValue = false;
            sub.FindPropertyRelative("messages").ClearArray();

            sub.isExpanded = true;
        };
    }
コード例 #47
0
    void subscribeToNPCEvents(NPCController npc)
    {
        npc.OnCollidedWithPlayer += callNPCEncounterEvent;

        if (!Tutorial.Playing()) {
            npc.OnOffscreen += handleNPCOffscreen;
        }
    }
コード例 #48
0
    void setNPCStartPosition(NPCController npc, SpawnPoint spawnPoint)
    {
        npc.transform.position =
            SpawnPointController.GetSpawnPosition(spawnPoint, true);

        npc.moveAcrossScreenToLeft();
    }
コード例 #49
0
 void setNPCReferences(NPCController npc, SpawnPoint spawnPoint)
 {
     npc.SetSpawnPoint(spawnPoint);
     subscribeToNPCEvents(npc);
 }
コード例 #50
0
ファイル: PlayerController.cs プロジェクト: jchillerup/sadly
 public void PushPlayerAway(NPCController npc)
 {
     _pushSpeed += ((transform.position - npc.transform.position) * 6 + new Vector3(0, 1, 0)) * (float)Beverages/3.0f;
 }
コード例 #51
0
ファイル: PlayerInput.cs プロジェクト: TylerBoyes/MazePlat
    // Update is called once per frame
    void FixedUpdate()
    {
        if (activeNPCDialog != null)
        {
            if (activeNPCDialog.DialogEnabled())
                return;
        }

        //Get input for starting NPC dialogs:
        if (setNpcAction)
        {
            setNpcAction = false;
            activeNPCDialog.Action();
        }
        else if (Input.GetButtonUp("Fire1"))
        {
            GameObject[] npcs = GameObject.FindGameObjectsWithTag("NPC");

            //get closes npc:
            if (npcs.Length > 0)
            {
                GameObject closestNPC = null;
                float closest = 2.00f; // min distance
                foreach (GameObject npc in npcs)
                {
                    float distance = Vector3.Distance(transform.position, npc.transform.position);
                    if (distance < closest)
                    {
                        closestNPC = npc;
                        closest = distance;
                    }
                }
                if (closestNPC != null)
                {
                    activeNPCDialog = closestNPC.GetComponent<NPCController>();
                    setNpcAction = true;
                }
            }
        }

        targetSpeed = Vector2.zero;

        targetSpeed.x = Input.GetAxisRaw("Horizontal");
        if (playerPhysics.onSolidGround)
            targetSpeed.y = Input.GetAxisRaw("Vertical");

        amountToMove = targetSpeed;

        if (jumpTime <= 0)
        {
            if (playerPhysics.grounded && !playerPhysics.onSolidGround)
            {
                if (Input.GetButton("Jump"))
                {
                    playerPhysics.Jump(JumpPower);
                    jumpTime = 0.2f;
                }
            }
        }
        else
            jumpTime -= Time.deltaTime;

        if (Mathf.Abs(playerPhysics.rigidbody2D.velocity.x) >= Speed)
            amountToMove.x = 0;
        if (Mathf.Abs(playerPhysics.rigidbody2D.velocity.y) >= Speed)
            amountToMove.y = 0;

        playerPhysics.Move(amountToMove * 1000 * Time.deltaTime * Acceleration);

        currentSpeed = playerPhysics.rigidbody2D.velocity;
    }
コード例 #52
0
        static void Main(string[] args)
        {
            Config = new NetPeerConfiguration("pokemon");
            Config.Port = 7377;
            Config.MaximumConnections = 20;
            Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            Server = new NetServer(Config);

            Server.Start();

            Console.WriteLine("time to own");

            /*/Creating a ContentManager to load maps from XML
            Form form = new Form();
            GraphicsDeviceService gds = GraphicsDeviceService.AddRef(form.Handle,
                    form.ClientSize.Width, form.ClientSize.Height);

            ServiceContainer services = new ServiceContainer();
            services.AddService<IGraphicsDeviceService>(gds);
            content = new ContentManager(services, "Content");*/

            //Initialize all the maps here

            List<PlayerPrimitive> Players = new List<PlayerPrimitive>();

            ServerNPCController = new NPCController();
            NPC npc = new NPC(null, new Vector2(15, 15), 2);
            ServerNPCController.addNPC(npc);

            NetIncomingMessage nic;

            DateTime time = DateTime.Now;

            TimeSpan updateSpan = new TimeSpan(0, 0, 0, 0, 30);

            Console.WriteLine("Waiting for players to join...");

            while (true)
            {
                if ((nic = Server.ReadMessage()) != null)
                {
                    switch (nic.MessageType)
                    {
                        case NetIncomingMessageType.ConnectionApproval :
                            if (nic.ReadByte() == (byte)PacketTypes.Login)
                            {
                                Console.WriteLine("New Player joining.");

                                nic.SenderConnection.Approve();

                                PlayerPrimitive prim = DataReadWrite.ReadPlayer(nic);
                                prim.Connection = nic.SenderConnection;

                                Players.Add(prim);

                                Console.WriteLine("The following players are in:");
                                foreach (PlayerPrimitive player in Players)
                                {
                                    Console.WriteLine(player.Name + " joined " + System.DateTime.Now);
                                    Console.WriteLine(player.UniqueId);
                                }

                                NetOutgoingMessage outmsg = Server.CreateMessage();

                                outmsg.Write((byte)PacketTypes.WorldState);

                                outmsg.Write(Players.Count);

                                foreach (PlayerPrimitive player in Players)
                                {
                                    outmsg.WriteAllProperties(player);
                                }

                                Server.SendMessage(outmsg, nic.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);

                                Console.WriteLine("New player has joined, server updated and shit.");

                            }
                            break;

                        case NetIncomingMessageType.Data :

                            if (nic.ReadByte() == (byte)PacketTypes.Move)
                            {
                                foreach (PlayerPrimitive player in Players)
                                {
                                    if (player.Connection != nic.SenderConnection)
                                        continue;

                                    Vector2 position = XNAExtensions.ReadVector2(nic);
                                    bool running = nic.ReadBoolean();

                                    player.X = (int)position.X;
                                    player.Y = (int)position.Y;
                                    player.IsRunning = running;

                                    Console.WriteLine(player.Name + " position: " + player.X + ", " + player.Y + ": running = " + running);

                                    /*NetOutgoingMessage outmsg = Server.CreateMessage();

                                    outmsg.Write((byte)PacketTypes.WorldState);
                                    outmsg.Write(Players.Count);

                                    foreach (PlayerPrimitive playa in Players)
                                        outmsg.WriteAllProperties(playa);

                                    Server.SendMessage(outmsg, Server.Connections, NetDeliveryMethod.ReliableOrdered, 0);*/
                                    break;
                                }

                            }

                            break;

                        case NetIncomingMessageType.StatusChanged :

                            Console.WriteLine(nic.SenderConnection.ToString() + " status changed." + (NetConnectionStatus)nic.SenderConnection.Status);

                            if (nic.SenderConnection.Status == NetConnectionStatus.Disconnected ||
                                nic.SenderConnection.Status == NetConnectionStatus.Disconnecting)
                            {
                                foreach (PlayerPrimitive player in Players)
                                {
                                    if (player.Connection == nic.SenderConnection)
                                    {
                                        Players.Remove(player);
                                        Console.WriteLine(player.Name + " left the game " + System.DateTime.Now);
                                        break;
                                    }
                                }
                            }
                            break;

                        default :

                            Console.WriteLine("Message type is: " + nic.MessageType);

                            break;
                    }
                }

                if ((time + updateSpan) < DateTime.Now)
                {
                    ServerNPCController.UpdateNPCs(updateSpan);

                    if (Server.ConnectionsCount > 0)
                    {
                        NetOutgoingMessage outmsg = Server.CreateMessage();
                        outmsg.Write((byte)PacketTypes.WorldState);
                        outmsg.Write(Players.Count);
                        outmsg.Write(ServerNPCController.NPCs.Count);

                        foreach (PlayerPrimitive player in Players)
                            outmsg.WriteAllProperties(player);

                        foreach (NPC nerdo in ServerNPCController.NPCs)
                            outmsg.WriteAllProperties(nerdo.toPrimitive());

                        Server.SendMessage(outmsg, Server.Connections, NetDeliveryMethod.ReliableOrdered, 0);
                    }

                    time = DateTime.Now;
                }

                System.Threading.Thread.Sleep(1);
            }
        }
コード例 #53
0
    private void spawnNPC()
    {

        npc = TrashMan.spawn("NPC", PlayerController.PC.transform.position - new Vector3(6,6, 0)).GetComponent<NPCController>();
        npc.initializeNPC();
        setObjective(npc.transform);
        npc.objectiveController.set(objective);
    }
コード例 #54
0
	void Awake(){
		_instance = this;
	}
コード例 #55
0
    void Start()
    {
        npc = gameObject.GetComponent<NPCController>();
        rNum = Random.Range(1, 4);

         objPlayer = GameObject.FindGameObjectWithTag("Player");

        if (objPlayer != null)
        {
            scoreController = objPlayer.GetComponent<PlayerController>();
        }
        if (scoreController == null)
        {
            Debug.Log("Cannot find 'PlayerController' script");
        }
    }
コード例 #56
0
    /// <summary>
    /// Set up references and initialize lists. Start the creation 
    /// of the initial movement plan, and then start the movement.
    /// </summary>
    void Start()
    {
        //Init
        routeDestinations = new List<RouteDataObject>();

        //References
        self = gameObject.GetComponent<NPC>();
        GameObject sectorController = GameObject.Find("SectorController");
        if (sectorController != null)
        {
            sc = sectorController.GetComponent<SectorController>();
            nc = sectorController.GetComponent<NPCController>();
        }
        else
        {
            throw new System.Exception("SectorController was not found. Is it present and named 'SectorController'?");
        }

        //Plan setup
        SetMovementPlan();
    }
コード例 #57
0
    private void NewGame()
    {
        MarketController mc = new MarketController();
        mc.LoadCommodityShopInventories();

        NPCController nc = new NPCController();
        nc.LoadNewMerchants();
    }
コード例 #58
0
ファイル: CRController.cs プロジェクト: silantzis/quest
 /// npc threat management
 public void aggro(NPCController npc)
 {
     if (!_aggroList.Contains(npc))
         _aggroList.Add(npc);
 }
コード例 #59
0
ファイル: Tutorial.cs プロジェクト: imann24/peace-superheroes
    void handleNPCEncounter(Emotion emotion, string phrase, NPCController npc)
    {
        canvas.sortingOrder++;

        if (emotion == Emotion.None) {
            PhraseApprover.Instance.ToggleRejectButton(false);
            StepForwardInTutorial();
        } else if (emotion == Emotion.Mad) {
            ShowCurrentSlide();
            timedTickTutorial(5f);
        }
    }
コード例 #60
0
 public void SetNPC(NPCController npc)
 {
     this.npc = npc;
 }