Beispiel #1
0
    private void Update()
    {
        if (dead)
        {
            return;
        }
        if (gameObject.CompareTag("Preview"))
        {
            return;
        }

        UnitActions.Move(this);
        UpdateMovingAnimation();
        UnitActions.UpdateIsSwimming(this);

        updateCounter = (updateCounter + 1) % GameManager.gameManager.countsBetweenUpdates;
        if (updateCounter == 0)
        {
            UnitActions.SetThought(this);
            //UnitActions.WanderIfDeadTarget(this);
            UnitActions.HungerEffect(this);
            UnitActions.ThirstEffect(this);
            UnitActions.TurnHungryChance(this);
            UnitActions.TurnThirstyChance(this);
            UnitActions.TurnHornyChance(this);
            UnitActions.HealthRegenEffect(this);
            unitState = UnitStateMachine.NextState(this);
        }
    }
Beispiel #2
0
    public void SetUpPanel()
    {
        SM = GetComponentInParent <UnitStateMachine>();

        GetComponent <Image>().color = WaitColor;
        SM.ChangeStatusToMove       += ChangeColorToMove;
        SM.ChangeStatusToIdle       += ChangeColorToIdle;
    }
Beispiel #3
0
    protected override void OnStateEnter()
    {
        base.OnStateEnter();
        usm = (UnitStateMachine)stateMachine;

        engaging = Engage(usm.currentThreat);
        StartCoroutine(engaging);
    }
Beispiel #4
0
    void TriggerAttack()
    {
        Debug.Log("Player is attacking " + gameObject.name);
        UnitStateMachine u = ScriptToolbox.GetInstance().GetPlayerManager().player.GetComponent <UnitStateMachine>();

        u.currentThreat = transform;
        u.RequestChangeState(StateMachine.States.Fight);
    }
Beispiel #5
0
 void TriggerTrade()
 {
     if (myShop != null)
     {
         UnitStateMachine u = GetComponent <UnitStateMachine>();
         u.RequestChangeState(StateMachine.States.Shopping);
     }
     else
     {
         Debug.Log("This NPC cannot trade");
     }
 }
Beispiel #6
0
    protected override void Init()
    {
        base.Init();
        usm = (UnitStateMachine)stateMachine;

        canTransitionInto = new StateMachine.States[]
        {
            StateMachine.States.Idle,
            StateMachine.States.Incapacitated,
            StateMachine.States.Routed
        };
    }
Beispiel #7
0
    // Start is called before the first frame update
    public void Start()
    {
        rb = GetComponent <Rigidbody2D>();

        GetComponent <Damageable>().damageAction +=
            (n) => rb.AddForce(15 * Mathf.Sign(n.transform.lossyScale.x) * Vector2.right, ForceMode2D.Impulse);
        GetComponent <Damageable>().dieAction += () => Destroy(gameObject);

        motion = GetComponent <MoveXCommand>();

        attackCommand = GetComponent <ZombiAttack>();


        stateMachine = GetComponent <UnitStateMachine>();

        Patroler patroler = new Patroler(new StateInfo(transform, stateMachine), transform.position)
        {
            speed = BaseSpeed * 0.7f,
            time  = 3f
        };
        Follower follower = new Follower(new StateInfo(transform, stateMachine))
        {
            maxSpeed = BaseSpeed
        };
        MoveToPoint motionToPoint = new MoveToPoint(new StateInfo(transform, stateMachine), patroler.point, patroler)
        {
            speed = new Vector2(BaseSpeed * 0.8f, 0)
        };

        //stateMachine.SetState(patroler);
        stateMachine.Initialize(follower);


        target = GameObject.FindGameObjectWithTag(targetTag).GetComponent <Rigidbody2D>();
        follower.SetTarget(target);


        detectPlayer.Enter += () => stateMachine.SetState(follower);

        attackZone.Enter += () => stateMachine.SetState(new IdleState(new StateInfo(transform, stateMachine)));
        attackZone.Stay  += () => attackCommand.Execute();
        attackZone.Exit  += () => stateMachine.SetState(follower);

        //lostZone.Exit += () =>
        //{
        //    if (stateMachine.currentState == follower)
        //    {
        //        stateMachine.SetState(new WaitState(transform, stateMachine, 1, motionToPoint));
        //    }
        //};
    }
Beispiel #8
0
    protected override void OnStateEnter()
    {
        base.OnStateEnter();
        usm = (UnitStateMachine)stateMachine;

        if (wander)
        {
            StartCoroutine(Wander());
        }
        if (!doNotReact)
        {
            StartCoroutine(ScanArea());
        }
    }
        private void Update()
        {
            if (DebugTextBox == null)
            {
                return;
            }

            if (SM == null)
            {
                SM = GetComponent <UnitStateMachine>();
            }

            DebugTextBox.SetText(SM.CurrentState.ToString());
        }
Beispiel #10
0
    protected override void OnStateEnter()
    {
        base.OnStateEnter();

        UnitStateMachine usm = (UnitStateMachine)stateMachine;

        if (usm.unitTraits.courage <= Random.Range(0, 100)) //also check who's around to determine any other threats
        {
            stateMachine.RequestChangeState(StateMachine.States.Flight);
        }
        else
        {
            stateMachine.RequestChangeState(StateMachine.States.Fight);
        }
    }
Beispiel #11
0
    public void StartDialogue(Dialogue dialogue)
    {
        isOpen = true;
        dialogueWindow.SetBool("isOpen", isOpen);

        nameText.text = dialogue.name;
        unitTalking   = dialogue.unit;

        sentences.Clear(); //clear que of any old sentences

        foreach (string sentence in dialogue.sentences)
        {
            sentences.Enqueue(sentence); //adds sentances to our que
        }

        DisplayNextSentence();
    }
    // Start is called before the first frame update
    void Start()
    {
        stroke       = GetComponent <MorticianStroke>();
        charge       = GetComponent <MorticianCharge>();
        stateMachine = GetComponent <UnitStateMachine>();

        Follower follower = new Follower(new StateInfo(transform, stateMachine));

        player = GameObject.FindGameObjectWithTag("Player").transform;
        follower.SetTarget(player.GetComponent <Rigidbody2D>());
        follower.maxSpeed = 4f;
        stateMachine.Initialize(follower);

        idle = new IdleState(new StateInfo(transform, stateMachine));

        stroke.beginAttack += () => stateMachine.SetState(idle);
        stroke.endAttack   += () => stateMachine.SetState(follower);
    }
Beispiel #13
0
    public float bleedBonus     = 0f; //how rapidly we bleed from this part

    private void Start()
    {
        //might not want these in bodyparts because they're going to get called in every single body part in the game!
        myBrain        = GetComponent <Brain>();
        myBody         = GetComponent <BodyPartController>();
        myCombatSkills = GetComponent <CombatSkills>();
        anim           = GetComponent <UnitAnimController>();
        ai             = GetComponent <UnitReactions>();
        stateMachine   = GetComponent <UnitStateMachine>();

        if (dollPart != null)
        {
            dollPart.Initialize(PackagePartInfo());
        }

        MyWeapon(); //run this to make sure we hve unarmed weapon
        //Debug.Log("assigning parts for " + this);
        //Debug.Log("my armortype is " + armorType);
    }
Beispiel #14
0
    private void Start() //make private?
    {
        //unitReactions = GetComponent<UnitReactions>();
        stateMachine            = GetComponent <UnitStateMachine>();
        anim                    = GetComponent <UnitAnimController>();
        mySkills                = GetComponent <CombatSkills>();
        mySkills.onSkillGained += UpdateSkills;
        AddBodyParts();

        //if a unit doesn't have an equipment manager load default eqpmnt
        EquipmentManager e = GetComponent <EquipmentManager>();

        if (e == null)
        {
            GetComponent <DefaultEquipment>().EquipLoadout(this);
        }
        else
        {
            //let equipment handler load it's own default stuff if it needs to
            e.onEquipmentChanged += UpdateSkills;
        }
    }
Beispiel #15
0
 private void Start()
 {
     psm = ScriptToolbox.GetInstance().GetPlayerManager().player.GetComponent <UnitStateMachine>();
 }
Beispiel #16
0
 public override void OnInspectorGUI()
 {
     base.OnInspectorGUI();
     EditorGUILayout.LabelField("Hello, editor");
     UnitStateMachine state = this.target as UnitStateMachine;
 }
Beispiel #17
0
 private void Update()
 {
     unitState = UnitStateMachine.NextState(this);
 }
Beispiel #18
0
    //can be used for descriptions and observations as well
    void TriggerDialogue()
    {
        UnitStateMachine u = GetComponent <UnitStateMachine>();

        u.RequestChangeState(StateMachine.States.Talking);
    }