Example #1
0
        public virtual IBrain getNoBrain(AICharacter character)
        {
            IBrain noBrain = new NPCNoBrain();

            noBrain.init(character);
            return(noBrain);
        }
    public override void GetTargeter(Character _character)
    {
        SpaceContextualActions.Clear();


        for (int i = 0; i < TilePawnIsOn.neighbors.Count; i++)
        {
            if (TilePawnIsOn.neighbors[i].TargetableOnTile is AICharacter)
            {
                customer = (AICharacter)TilePawnIsOn.neighbors[i].TargetableOnTile;
                // for(int j = 0; j < _character.cariedObjects.Count; j++)
                //{
                //    if(_character.cariedObjects[j] is Food)
                //    {
                //        PlayercontrolledCharacter givingCharacter = (PlayercontrolledCharacter)_character;
                //        SpaceContextualActions.Add(new GiveItem(TilePawnIsOn,givingCharacter, j));
                //    }
                //}

                if (!customer.OrderHasBeenTaken)
                {
                    SpaceContextualActions.Add(new TakeOrder(_character, customer));
                }
            }
        }
    }
Example #3
0
    private Transform player;                                           // Reference to the player's transform.

    public AIBehaviorAggressive(AICharacter character)
    {
        enemySight         = character.gameObject.GetComponent <EnemySight>();
        player             = GameObject.FindGameObjectWithTag(Tags.player).transform;
        playerHealth       = player.GetComponent <PlayerHealth>();
        lastPlayerSighting = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent <LastPlayerSighting>();
    }
Example #4
0
    AICharacter setUpCharacter(AICharacter aICharacter, Tile targetTile)
    {
        aICharacter.ChooseWhatToEat(_desireContainer.chooseWhatToEatBasedOnTaste(aICharacter.Race));
        aICharacter.characterCoaster = _monoPool.GetCharacterCoasterInstance();
        aICharacter._monoPool        = _monoPool;
        aICharacter.characterCoaster.SetArtForFacing(EnumHolder.Facing.Up);

        if (targetTile.EntityTypeOnTile == EnumHolder.EntityType.Clear)
        {
            aICharacter.TilePawnIsOn = targetTile;
            aICharacter.TilePawnIsOn.EntityTypeOnTile = EnumHolder.EntityType.Character;
        }

        else
        {
            for (int i = 0; i < targetTile.neighbors.Count; i++)
            {
                if (targetTile.neighbors[i].EntityTypeOnTile == EnumHolder.EntityType.Clear)
                {
                    aICharacter.TilePawnIsOn = targetTile.neighbors[i];
                    aICharacter.TilePawnIsOn.EntityTypeOnTile = EnumHolder.EntityType.Character;
                    break;
                }
            }
        }

        return(aICharacter);
    }
Example #5
0
        public void Execute(AICharacter character, IGoal goal)
        {
            List <IInspectable> inspectables = FindInspectablesInView(character);

            inspectables.Sort(delegate(IInspectable x, IInspectable y) {
                return((character.Position - x.Position).magnitude.CompareTo((character.Position - y.Position).magnitude));
            });
            IInspectable inspectable = inspectables.Find(delegate(IInspectable obj) {
                return(!character.Knows(obj));
            });

            if (inspectable == null)
            {
                NavMeshAgent agent = character.gameObject.GetComponent <NavMeshAgent> ();
                NavMeshHit   navHit;

                do
                {
                    NavMesh.SamplePosition(UnityEngine.Random.insideUnitSphere * agent.speed + character.Position, out navHit, agent.speed, -1);
                } while (character.ExploredArea.Contains(navHit.position));

                character.AddGoal(new Goal(new List <IRequirement> ()
                {
                    new AtPosition(navHit.position)
                }, goal));
            }
            else
            {
                character.AddGoal(new Goal(new List <IRequirement> ()
                {
                    new Inspected(inspectable)
                }, goal));
            }
        }
Example #6
0
    protected override void Initialize()
    {
        owner = GetComponentInParent <AICharacter>();

        this.Observe(Message.AI_ReachedWaypoint);
        this.Observe(Message.AI_StartAttack);
        this.Observe(Message.Combat_AttackEnd);
        this.Observe(Message.Combat_Stagger);
        this.Observe(Message.Combat_StaggerEnd);
        this.Observe(Message.Combat_Death);

        transitions = new StateTransition[] {
            new StateTransition(States.CombatMovement, States.Seeking, () => { return(owner.GetDistanceToTarget() > 12f); }),
            new StateTransition(States.Default, States.Patrolling, () => { return(CurrentStateTime > 2f); }),
            new StateTransition(States.Default, States.Seeking, () => { return(owner.HasTarget); }),
            new StateTransition(States.Patrolling, States.Seeking, () => { return(owner.HasTarget); }),
            new StateTransition(States.Seeking, States.CombatMovement, () => { return(owner.GetDistanceToTarget() < 5f); }),
            new StateTransition(States.CombatMovement, States.Default, () => {
                if (owner.Target.IsInAnyState(States.Dead))
                {
                    owner.Target = null;
                    return(true);
                }
                return(false);
            })
        };
    }
Example #7
0
        public override float GetUtility(Character enemyCharacter, AICharacter ai)
        {
            if (AIMelee.IsEndState(ai.parent.state))
            {
                return(0.0f);
            }

            switch (ai.parent.state)
            {
            case Character.State.Attack:
                return(0.0f);
            }

            if (enemyCharacter == null)
            {
                return(0.1f);
            }

            if (ai.parent.NextAttackOn() == true)
            {
                return(0.0f);
            }

            if (MagiUtil.IsInRange(enemyCharacter.transform.position - ai.parent.transform.position, ai.parent.keepDistance + enemyCharacter.radius) == false)
            {
                return(0.0f);
            }

            return(0.1f);
        }
        static void ParseAll()
        {
            AICCollection collection = new AICCollection();

            foreach (string file in Directory.EnumerateFiles("decompiled", "*.txt"))
            {
                string name = Path.GetFileNameWithoutExtension(file);
                if (!Enum.TryParse(name, true, out AICIndex index))
                {
                    continue;
                }

                Console.WriteLine(index);
                using (StreamReader sr = new StreamReader(file))
                {
                    AICharacter aic = new AICharacter()
                    {
                        Index       = (int)index,
                        Name        = index.ToString(),
                        Personality = Parse(sr)
                    };
                    collection.Add((int)index, aic);
                }
            }

            using (FileStream fs = new FileStream("vanilla.aic", FileMode.Create))
                collection.Write(fs);
        }
Example #9
0
    public void OnTriggerEnter(Collider other)
    {
        PlayerCharacter player = other.GetComponent <PlayerCharacter>();

        if (player)
        {
            if (player.enabled)
            {
                player.Die();
            }
        }

        AICharacter ai = other.GetComponent <AICharacter>();

        if (ai)
        {
            if (ai.enabled)
            {
                ai.Die();
            }
        }
        if (other.transform.tag == "Slicable" && !other.isTrigger)
        {
            //planeDummy.eulerAngles = Vector3.zero;
            SliceObject(other.GetComponentInChildren <Renderer>().gameObject, cuttingPlane);

            /*  if ( )
             * {
             *    if (other.transform.parent != null)
             *        other.transform.parent.gameObject.SetActive(false);
             * }*/
        }
    }
Example #10
0
    public override void processPrimaryHit(Item item, GameObject hit, Vector3 hitPoint, Vector3 direction)
    {
        Rigidbody rig = hit.transform.GetComponent <Rigidbody>();

        if (hit.GetComponent <Collider>().gameObject.GetComponent <Rigidbody>() != null)
        {
            rig.AddForce((hit.GetComponent <Collider>().transform.position - item.transform.position).normalized * force);
        }

        Collider[] objects = Physics.OverlapSphere(hitPoint, blastRadius);
        foreach (var colliderObject in objects)
        {
            Rigidbody rigid = colliderObject.gameObject.GetComponent <Rigidbody>();
            if (rigid != null)
            {
                AICharacter c = colliderObject.GetComponent <AICharacter>();
                if (c != null)
                {
                    c.gameObject.AddComponent <RagdollEffect>().startEffect(1.5f);
                    rigid = c.childBody;
                }


                Vector3 displacement = colliderObject.transform.position - hitPoint;
                rigid.AddForce(force * Mathf.Clamp(1 - displacement.magnitude / blastRadius, 0, 1) * displacement.normalized);
            }
        }
        playPrimaryOnHitEffect(null, hitPoint);
    }
Example #11
0
        public AICharacterController getAICharacterController(AICharacter character, IBrainFactory factory)
        {
            AICharacterController controller = new AICharacterController();

            controller.init(character, factory);
            return(controller);
        }
Example #12
0
        public override void update(AICharacter character)
        {
            IGravityClient gravityClient  = character.getEntity().getGravityClient();
            KeysPressed    keysPressed    = character.getEntity().getKeysPressed();
            RayInformation rayInformation = character.getEntity().getGravityClient().getRayInformation();
            RayHitboxes    rayHitboxes    = gravityClient.getRayHitboxes();

            gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, false);
            gravityClient.getRayInformation().checkRaysBelow(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 270.0f, layermask, false);

            float minimalSpaceBetweenTileBelow = rayInformation.MinimalSpaceBetweenTileBelow;
            float topFrontDistance             = (rayHitboxes.HitTopFront.distance * 0.9f);
            bool  turned = false;

            gravityClient.getRayInformation().checkRaysFront(gravityClient, 0.0f, character.getEntity().getTransform().eulerAngles.z + 0.0f, layermask, true);

            keysPressed = turnIfWallIsNear(gravityClient, topFrontDistance,
                                           rayInformation.MinimalSpaceBetweenTileFront, keysPressed, out turned);

            if (!turned && (rayHitboxes.HitMiddleBelow.collider.tag.CompareTo("Slope") != 0))
            {
                keysPressed = turnIfOnAnEdge(keysPressed, minimalSpaceBetweenTileBelow, character);
            }
            character.setKeysPressed(keysPressed);
        }
Example #13
0
        private KeysPressed turnIfOnAnEdge(KeysPressed keysPressed,
                                           float minimalSpaceBetweenTileBelow, AICharacter character)
        {
            IGravityClient gravityClient = character.getEntity().getGravityClient();
            RayHitboxes    rayHitboxes   = gravityClient.getRayHitboxes();

            if (gravityClient.isFlipped() && rayHitboxes.HitLeftBelow.distance > 1.0f)
            {
                keysPressed.left  = false;
                keysPressed.right = true;
            }
            else if (gravityClient.isFlipped() &&
                     rayHitboxes.HitLeftBelow.distance <= minimalSpaceBetweenTileBelow)
            {
                keysPressed.left  = true;
                keysPressed.right = false;
            }

            if (!gravityClient.isFlipped() &&
                rayHitboxes.HitRightBelow.distance > 1.0f)
            {
                keysPressed.left  = true;
                keysPressed.right = false;
            }
            else if (!gravityClient.isFlipped() &&
                     rayHitboxes.HitRightBelow.distance <= minimalSpaceBetweenTileBelow)
            {
                keysPressed.left  = false;
                keysPressed.right = true;
            }

            return(keysPressed);
        }
Example #14
0
    private IEnumerator CharacterDeath()
    {
        if (character != null)
        {
            EventManager.TriggerEvent <CharacterEvent>(new CharacterEvent(CharacterEventType.Death, character));

            character.characterStateMachine.ChangeState(Character.CharacterState.Dead);
            yield return(null);

            yield return(new WaitForSecondsRealtime(
                             character.CharacterAnimator.GetCurrentAnimatorStateInfo(0).length + 0.15f
                             ));

            if (drop != null)
            {
                AICharacter isAICharacter = character as AICharacter;
                if (isAICharacter != null)
                {
                    Pickable _drop = Instantiate(drop, transform.position, transform.rotation);
                    _drop.InitializePickableValue(isAICharacter.Reward);
                }
            }
        }

        yield break;
    }
Example #15
0
        private List <IInspectable> FindInspectablesInView(AICharacter character)
        {
            List <IInspectable> inspectables = new List <IInspectable> ();

            RaycastHit[] castStar = Physics.SphereCastAll(character.transform.position, 165, Vector3.forward, 50);
            foreach (RaycastHit raycastHit in castStar)
            {
                if (raycastHit.collider.GetComponentInChildren <AICharacter>() != character)
                {
                    IInspectable inspectable = null;
                    if (raycastHit.collider.GetComponentInChildren <IInspectable>() != null)
                    {
                        inspectable = raycastHit.collider.GetComponentInChildren <IInspectable> ();
                    }
                    else if (raycastHit.collider.GetComponentInParent <IInspectable>() != null)
                    {
                        inspectable = raycastHit.collider.GetComponentInParent <IInspectable> ();
                    }
                    if (inspectable != null && !inspectables.Contains(inspectable))
                    {
                        inspectables.Add(inspectable);
                    }
                }
            }
            return(inspectables);
        }
Example #16
0
        private void Start()
        {
            ai = character as AICharacter;
            Assert.IsNotNull(ai, "PatrollingState should only be entered by an AI character");

            StartCoroutine(Patrol());
        }
Example #17
0
    public override void processSecondaryHit(Item item, GameObject hit, Vector3 hitPoint, Vector3 direction)
    {
        if (current == null)
        {
            current = Instantiate(whalePrefab, (hitPoint + new Vector3(0, 15, 0)), new Quaternion());
            current.setEffectValues(item, this);
            current.setPrimaryEffect(false);
        }
        else
        {
            Collider[] objects = Physics.OverlapSphere(hitPoint, blastRadius);
            foreach (var colliderObject in objects)
            {
                Rigidbody rigid = colliderObject.gameObject.GetComponent <Rigidbody>();
                if (rigid != null)
                {
                    AICharacter c            = colliderObject.GetComponent <AICharacter>();
                    Vector3     displacement = colliderObject.transform.position - hitPoint;
                    if (c != null)
                    {
                        c.gameObject.AddComponent <RagdollEffect>().startEffect(1.5f);

                        c.takeDamage(0.5f * damage * Mathf.Clamp(1 - displacement.magnitude / blastRadius, 0, 1));
                    }
                    rigid.AddForce(force * Mathf.Clamp(1 - displacement.magnitude / blastRadius, 0, 1) * displacement.normalized, ForceMode.VelocityChange);
                }
            }
            current = null;
            base.processSecondaryHit(item, hit, hitPoint, direction);
        }
    }
Example #18
0
        public virtual IBrain getMoveBrain(AICharacter character)
        {
            IBrain moveBrain = new NPCMoveBrain();

            moveBrain.init(character);
            return(moveBrain);
        }
Example #19
0
    public void OnCollisionEnter(Collision other)
    {
        if (!shotForward)
        {
            return;
        }
        if (getLifeTimer() == null)
        {
            setLifeTimer(new GenericTimer(1, false));
        }
        if (other.transform.root == transform.root)
        {
            return;
        }

        AICharacter c = other.gameObject.GetComponent <AICharacter>();
        Rigidbody   r = other.gameObject.GetComponent <Rigidbody>();

        if (c != null)
        {
            r = c.childBody;
            c.takeDamage(50);
            c.gameObject.AddComponent <RagdollEffect>().startEffect(1);
        }
        if (r != null)
        {
            r.AddForce(other.impulse);
        }
    }
Example #20
0
 public virtual void SetTargetAI(AICharacter target)
 {
     if (TargetAI == null)
     {
         TargetAI = target;
     }
 }
Example #21
0
        public void Execute(AICharacter character, IGoal goal)
        {
            NavMeshAgent agent = character.gameObject.GetComponent <NavMeshAgent> ();

            character.target.transform.position = this.position;
            character.target.SetActive(true);
            agent.SetDestination(this.position);
        }
Example #22
0
 public void OnRemoveChar(AICharacter aic)
 {
     if (OverlapCharacters.Contains(aic))
     {
         aic.OnExitZone(this);
         OverlapCharacters.Remove(aic);
     }
 }
Example #23
0
 public static bool IsHaveObject(AICharacter aic, string zone)
 {
     if (m_instance.m_registeredZones.ContainsKey(zone))
     {
         return(m_instance.m_registeredZones[zone].IsHaveObject(aic));
     }
     return(false);
 }
Example #24
0
 public float CalculateCost(AICharacter character)
 {
     if (startCount == 0)
     {
         startCount = character.ExploredArea.Count;
     }
     return((float)requirement.Distance - (character.ExploredArea.Count - startCount));
 }
Example #25
0
 public bool IsFullfilled(AICharacter character)
 {
     if (currentExploredArea < 0)
     {
         currentExploredArea = character.ExploredArea.Count;
     }
     return(character.ExploredArea.Count - currentExploredArea >= distance);
 }
Example #26
0
 public void OnAddChar(AICharacter aic)
 {
     if (!OverlapCharacters.Contains(aic))
     {
         aic.OnEnterZone(this);
         OverlapCharacters.Add(aic);
     }
 }
Example #27
0
    public override void SetTargetAI(AICharacter target)
    {
        base.SetTargetAI(target);

        foreach (BTNode node in children)
        {
            node.SetTargetAI(TargetAI);
        }
    }
 private void OnCustomerStart(AbstractPawn customerCharacter)
 {
     if (customerCharacter is AICharacter)
     {
         AICharacter c = (AICharacter)customerCharacter;
         MoveCameraToPawn(c);
         camera.onStopMoving = c.MoveCharacter;
     }
 }
    private void Start()
    {
        int l = (m_Prefab.Length);

        for (int i = 0; i < m_SpawnCount; ++i)
        {
            AICharacter c = Instantiate(m_Prefab[i % l], m_SpawnPos.position + new Vector3(i * 1.0f + 1.0f, 0.0f, (i % 10)), Quaternion.identity).GetComponent <AICharacter>();
        }
    }
    private void Start()
    {
        shootingScript = GetComponent <EnemyShooting>();
        fsm            = GetComponent <AICharacter>();

        viewRadius = mech.range;

        StartCoroutine("SearchForTgts", searchDelay);
    }
Example #31
0
	public void getAICharNeighbors(List<AICharacter> listOfNeighbors, AICharacter currentChar, float radius)
	{
		Vector3 dist;
		
		foreach(AICharacter aiChar in listOfAICharacters)
		{
			if(currentChar==aiChar) continue;
			
			dist = aiChar.transform.position - currentChar.transform.position;
			if(dist.magnitude<radius)
			{
				listOfNeighbors.Add(aiChar);	
			}
		}
	}
Example #32
0
        public void CreateChild(Character mother, Character father)
        {
            Gender gender = (Gender)GetRandom(2);
            string name = gender == Gender.Female ? GetRandomFemaleName() : GetRandomMaleName();

            Character child = new AICharacter(name, CurrentTime, mother.Spouse.Dynasty, 0, this, gender);
            child.AssignParents(mother, father);

            characters.Add(child);
        }
Example #33
0
        public AICharacter GetRandomAICharacter()
        {
            Dynasty dynasty = GetRandomDynasty();
            int birthdate = GetAdultBirthdate();
            AICharacter character = new AICharacter(GetRandomMaleName(), birthdate, dynasty, 100, this, Gender.Male);

            AssignFamily(character);
            modifierManager.AssignInitialTraits(this, character, 4);
            return character;
        }
Example #34
0
        private void AssignFamily(Character character)
        {
            int wifeBirthdate = GetWifeBirthdate(character.BirthDate);

            Room home = roomManager.MakeUniqueRoom("ESTATE_ROOM");
            // All character have a wife for now.
            AICharacter spouse = new AICharacter(GetRandomFemaleName(), wifeBirthdate, character.Dynasty, 50, this, Gender.Female);
            characters.Add(spouse);

            // Now add a random number of children with random genders.
            List<Character> children = new List<Character>();
            int numChildren = GetRandom(MAX_CHILDREN);
            for (int i = 0; i < numChildren; i++)
            {
                Gender gender = (Gender)GetRandom(2);
                string name = gender == Gender.Female ? GetRandomFemaleName() : GetRandomMaleName();

                Character child = new AICharacter(name, GetChildBirthdate(wifeBirthdate), character.Dynasty, 5, this, gender);
                children.Add(child);
                characters.Add(child);
            }

            character.AssignFamily(spouse, children, home, cvManager.CreateRandomDNA(character, this), cvManager.CreateRandomDNA(spouse, this));
        }
Example #35
0
 public void Register(AICharacter character)
 {
     aiCharacters.AddOnce(character);
 }
Example #36
0
 public void Unregister(AICharacter character)
 {
     aiCharacters.Remove(character);
 }
Example #37
0
	public void Init() 
	{
		mCharacter = GetComponent<AICharacter>();
		ignoreWeightCalculations = false;
	}
Example #38
0
	public void RemoveCharacter(AICharacter aiChar)
	{
		listOfAICharacters.Remove(aiChar);	
	}
Example #39
0
	public void AddCharacter(AICharacter aiChar)
	{
		listOfAICharacters.Add(aiChar);
	}
Example #40
0
	void Start() {
		Init();
		targetCharacter = targetGO.GetComponent<AICharacter>();
		mCharacter.addBehavior(this);
	}
Example #41
0
 public DataFormat(AICharacter character, byte[] length)
 {
     this._character = character;
     this._length = length;
 }