Example #1
0
        // Update is called once per frame
        void Update()
        {
            _frameLengthStopwatch.Start();

            int giveControlCountPerActor   = 5;           // empiric
            int actorsToProcessInThisFrame = _actors.Count * giveControlCountPerActor;

            _actors = _gameContext.Actors.ToList();
            for (int i = 0; i < actorsToProcessInThisFrame; i++)
            {
                ActorBehaviour currentActor           = _actors[_currentActorIndex];
                bool           passControlToNextActor = true;

                if (currentActor.ActorData.Health > 0)
                {
                    passControlToNextActor = currentActor.GiveControl();
                }
                if (passControlToNextActor == false)
                {
                    return;
                }

                _currentActorIndex = (_currentActorIndex + 1) % _gameContext.Actors.Count;

                // if this frame is taking too long time (giving FPS<100), finish it, so that UI can catch up
                const int frameLengthForFps100 = 10;
                if (_frameLengthStopwatch.ElapsedMilliseconds > frameLengthForFps100)
                {
                    _frameLengthStopwatch.Reset();
                    return;
                }
            }
        }
 public void Awake()
 {
     animator = GetComponent<PlayerAnimationBehavior>();
     actor = GetComponent<ActorBehaviour>();
     actor.setSpeed(speed);
     physicsmg = GetComponent<PhysicsManager>();
 }
        public override void InstallBindings()
        {
            // create default bindings
            Container.Bind(x => x.AllInterfaces()
                           .Where(i =>
                                  i != typeof(IGameContext) &&
                                  i != typeof(IGameConfig) &&
                                  i != typeof(IUiConfig) &&
                                  i != typeof(IRandomNumberGenerator) &&
                                  i != typeof(IInputHolder)
                                  )
                           )
            .To(x => x.AllNonAbstractClasses().InNamespaces("Assets.Scripts"))
            .AsSingle();

            Container.Bind <IGameContext>().FromInstance(_gameContext).AsSingle();
            Container.Bind <IGameConfig>().FromInstance(_gameConfig).AsSingle();
            Container.Bind <IUiConfig>().FromInstance(_uiConfig).AsSingle();
            int rngSeed = _gameConfig.RngSeed == 0 ? Random.Range(0, int.MaxValue) : _gameConfig.RngSeed;

            Container.Bind <IRandomNumberGenerator>().FromInstance(new RandomNumberGenerator(rngSeed)).AsSingle();
            Container.Bind <IInputHolder>().To <InputHolder>().AsSingle();

            ItemBehaviour  itemPrefab  = Resources.Load <ItemBehaviour>("Prefabs/Item");
            ActorBehaviour actorPrefab = Resources.Load <ActorBehaviour>("Prefabs/Actor");

            Container.BindFactory <ItemBehaviour, ItemBehaviour.Factory>().FromComponentInNewPrefab(itemPrefab);
            Container.BindFactory <ActorBehaviour, ActorBehaviour.Factory>().FromComponentInNewPrefab(actorPrefab);

            Container.Bind <Material>().FromInstance(Resources.Load <Material>("Materials/Plain"))
            .WhenInjectedInto <PathRenderer>();
        }
Example #4
0
    public override void Interact(ActorBehaviour interactee)
    {
        //bara spelaren kan interacta med items?
        if (interactee != GameManager.player)
        {
            return;
        }

        if (item is Weapon)
        {
            PlayerData.SetWeapon(item as Weapon);
        }
        //vi sparar inte consumables permanent
        else if (!item.isConsumable)
        {
            PlayerData.AddItems(item);
        }

        //äckligt att behöva invertera såhär
        PlayerData.GetStat(StatType.Health).UpdateCurrent(-item.hpModifier);

        if (interactSounds != null && interactSounds.Length > 0)
        {
            AudioManager.Play(SFXType.Oneshot, interactSounds.RandomItem(null), Random.Range(.75f, 1.25f));
        }

        if (destroyAfterInteract)
        {
            base.tile.SetType(TileType.Floor);
            base.tile.SetEntity(null);

            Destroy(this.gameObject);
        }
    }
Example #5
0
        public ActorBehaviour SpawnActor(ActorType actorType, Vector2Int position, bool isBoss = false)
        {
            ActorBehaviour instantiatedActor = _actorBehaviourFactory.Create();

            instantiatedActor.name = actorType.ToString();
            ActorData actorData = instantiatedActor.ActorData;

            actorData.ActorType = actorType;
            actorData.IsBoss    = isBoss;

            ActorDefinition actorDefinition = _gameConfig.ActorConfig.GetDefinition(actorType);

            instantiatedActor.GetComponent <SpriteRenderer>().sprite = actorDefinition.Sprite;
            actorData.WeaponWeld      = _rng.Choice(actorDefinition.WeaponPool);
            actorData.SwordsFromSkill = actorDefinition.SwordsFromSkill;
            actorData.VisionRayLength = actorDefinition.VisionRayLength;
            actorData.EnergyGain      = actorDefinition.EnergyGain;
            actorData.Team            = actorDefinition.Team;
            actorData.MaxHealth       = actorDefinition.MaxHealth;
            actorData.Health          = actorDefinition.MaxHealth;
            actorData.Accuracy        = actorDefinition.Accuracy;
            actorData.XpGiven         = actorDefinition.XpGiven;
            actorData.Level           = actorDefinition.InitialLevel;
            actorData.Traits          = actorDefinition.InitialTraits.ToArray().ToList();
            actorData.AiTraits        = actorDefinition.AiTraits.ToArray().ToList();

            Vector2Int freePosition = GetPositionToPlaceActor(position);

            actorData.LogicalPosition = freePosition;
            instantiatedActor.RefreshWorldPosition();
            _gameContext.Actors.Add(instantiatedActor);
            instantiatedActor.gameObject.SetActive(true);
            return(instantiatedActor);
        }
Example #6
0
    static void CreateEnemies()
    {
        // Sätter till ett slumpmässigt värde mellan 1-4
        int enemyCount = room.random.Next(1, 2 + 1);

        // modifiera antalet fiender, med antalet fiender spelaren har dödat för att göra spelet svårare
        // (lägg till (PlayerData.enemiesKilled / 20) per rum
        enemyCount += PlayerData.enemiesKilled / 20;

        // Laddar in fiender från minnet
        GameObject[] enemies = Resources.LoadAll <GameObject>("Prefabs/Enemies/");

        // Börjar på noll, körs så länge i är mindre än enemyCount, och slutar när i är lika med enemyCount
        // För varje steg i loopen läggs +1 på i
        for (int i = 0; i < enemyCount; i++)
        {
            // Hämtar en random tile som går att gå på
            Tile s = room.GetRandomTraversable(2, 2);

            // Tar en slumpmässig fiende-prefab och kopierar mallen till positionen från tilen ovan
            GameObject e = Object.Instantiate(enemies[room.random.Next(0, enemies.Length)], s.position, Quaternion.identity, null);

            ActorBehaviour ab = e.GetComponent <ActorBehaviour>();
            actors.Add(ab);
            ab.SetPosition(s);
        }
    }
 public override void Execute(ActorBehaviour _source, UnitBehaviour[] _targets)
 {
     foreach (UnitBehaviour _target in _targets)
     {
         _target.ActionPoints -= Amount;
     }
 }
Example #8
0
    void CreateTestObject()
    {
        Property p = new Property();

        p.HP = 10;
        string         path  = "Player/Player_GA";
        ActorBehaviour actor = ActorManager.Instance.CreateActor(path, p, ActorType.TEST_OBJ, ActorGroup.FRIEND);
    }
Example #9
0
    void CreateVirsualObject()
    {
        Property p = new Property();

        p.HP = 10;
        string         path  = "";
        ActorBehaviour actor = ActorManager.Instance.CreateActor(path, p, ActorType.VIRSUAL_OBJ, ActorGroup.FRIEND);
    }
Example #10
0
        public void SetBehaviour(ActorBehaviour behaviour)
        {
            Behaviour?.Dispose();

            Behaviour = behaviour;
            Behaviour.SetActor(this);
            Behaviour.Initialize();
        }
Example #11
0
 // Use this for initialization
 void Start()
 {
     _actorBehaviour          = transform.parent.GetComponent <ActorBehaviour>();
     _pathToTargetRenderer    = transform.GetChild(0).GetComponent <LineRenderer>();
     _nextNodeRenderer        = transform.GetChild(1).GetComponent <SpriteRenderer>();
     _stepsToNextNodeRenderer = transform.GetChild(2).GetComponent <LineRenderer>();
     _destinationRenderer     = transform.GetChild(3).GetComponent <SpriteRenderer>();
     gameObject.SetActive(_gameConfig.ModeConfig.ShowPaths);
 }
Example #12
0
 public StrikeEffect(ActorData actorData, ActorData attackedActor, bool parried, bool isDaringBlow, IWeaponColorizer weaponColorizer)
 {
     _parried         = parried;
     _isDaringBlow    = isDaringBlow;
     _weaponColorizer = weaponColorizer;
     _attackedActorLogicalPosition = attackedActor.LogicalPosition;
     _actorBehaviour         = actorData.Entity as ActorBehaviour;
     _attackedActorBehaviour = attackedActor.Entity as ActorBehaviour;
 }
Example #13
0
    // Use this for initialization
    void Awake()
    {
        actor = GetComponent<ActorBehaviour>();
        r = GetComponentInChildren<Renderer>();

        screenCanvas = FindObjectOfType<Canvas>();

        healthSlider = Instantiate(healthPrefab) as Slider;
        healthSlider.transform.SetParent(screenCanvas.transform, false);
    }
Example #14
0
    public void RemoveBehaviour(ActorBehaviour actorBehaviour)
    {
        if (actorBehaviours.Contains(actorBehaviour))
        {
            actorBehaviours.Remove(actorBehaviour);
        }

        AssignActorReferences();
        actorBehaviour.TerminateBehaviour();
    }
Example #15
0
    // Use this for initialization
    void Awake()
    {
        actor = GetComponent <ActorBehaviour>();
        r     = GetComponentInChildren <Renderer>();

        screenCanvas = FindObjectOfType <Canvas>();

        healthSlider = Instantiate(healthPrefab) as Slider;
        healthSlider.transform.SetParent(screenCanvas.transform, false);
    }
Example #16
0
        private void Awake()
        {
            NavMeshAgent navigator = GetComponent <NavMeshAgent>();

            Behaviour       = new ActorBehaviour(this, new MovableAI(navigator), new StateMachine(this));
            StatusInstances = statusData.InitializeStatusInstancesFromStatusData();

            ListStatus = StatusInstances.Select(s => s.Value).ToList();

            Behaviour.Movement.Navigator.speed        = critterData.Speed;
            Behaviour.Movement.Navigator.acceleration = critterData.Acceleration;
        }
Example #17
0
    public void Awake()
    {
        actor = GetComponent<ActorBehaviour>();
        recorder = GetComponent<RecordBehavior>();
        hud = GetComponent<PlayerHUD>();

        // Record Player Start Position when the Scene Starts
        PlyrStartPos = GetComponent<Transform>().position;

        actor.setSpeed(speed);
        actor.setJumpForce(jumpForce);
    }
Example #18
0
    public void Awake()
    {
        actor    = GetComponent <ActorBehaviour>();
        recorder = GetComponent <RecordBehavior>();
        hud      = GetComponent <PlayerHUD>();

        // Record Player Start Position when the Scene Starts
        PlyrStartPos = GetComponent <Transform>().position;

        actor.setSpeed(speed);
        actor.setJumpForce(jumpForce);
    }
Example #19
0
        public override void DealDamage(int amount, Entity damageSource)
        {
            base.DealDamage(amount, damageSource);

            Behaviour?.OnActorDamageReceiveDamage(damageSource);

            if (Health <= 0 && Behaviour != null)
            {
                Behaviour.Dispose();
                Behaviour = null;
            }
        }
Example #20
0
    // Use this for initialization
    void Awake()
    {
        _actorBehaviour      = transform.parent.GetComponent <ActorBehaviour>();
        _frameSpriteRenderer = GetComponent <SpriteRenderer>();

        var maxSwords = _maxSwordsCalculator.Calculate(_actorBehaviour.ActorData);

        _actorBehaviour.ActorData.MaxSwords = maxSwords;
        _actorBehaviour.ActorData.Swords    = maxSwords;
        _maxSwordsShown = maxSwords;
        InitializeActiveSwords(maxSwords);
        SetFrameSpriteToMaxSwords(_maxSwordsShown);
    }
    public StateMachineActor(ActorBehaviour ab)
    {
        _actorBehaviour = ab;

        var idleState   = new ActorIdleState(this, _actorBehaviour);
        var walkState   = new ActorWalkState(this, _actorBehaviour);
        var fightState  = new ActorFightState(this, _actorBehaviour);
        var dieState    = new ActorDieState(this, _actorBehaviour);
        var vanishState = new ActorDieState(this, _actorBehaviour);

        var stateList = new Dictionary <FSMStateActor.StateEnum, IFsmState>
        {
            { FSMStateActor.StateEnum.IDLE, idleState },
            { FSMStateActor.StateEnum.WALK, walkState },
            { FSMStateActor.StateEnum.FIGHT, fightState },
            { FSMStateActor.StateEnum.DIE, dieState },
            { FSMStateActor.StateEnum.VANISH, vanishState },
        };

        SetStates(stateList);

        var allowedTransitions = new Dictionary <FSMStateActor.StateEnum, IList <FSMStateActor.StateEnum> >();

        allowedTransitions.Add(FSMStateActor.StateEnum.IDLE, new List <FSMStateActor.StateEnum>
        {
            FSMStateActor.StateEnum.WALK,
            FSMStateActor.StateEnum.FIGHT,
            FSMStateActor.StateEnum.DIE,
        });
        allowedTransitions.Add(FSMStateActor.StateEnum.WALK, new List <FSMStateActor.StateEnum>
        {
            FSMStateActor.StateEnum.IDLE,
            FSMStateActor.StateEnum.FIGHT,
            FSMStateActor.StateEnum.DIE,
        });
        allowedTransitions.Add(FSMStateActor.StateEnum.FIGHT, new List <FSMStateActor.StateEnum>
        {
            FSMStateActor.StateEnum.IDLE,
            FSMStateActor.StateEnum.WALK,
            FSMStateActor.StateEnum.DIE,
        });
        allowedTransitions.Add(FSMStateActor.StateEnum.DIE, new List <FSMStateActor.StateEnum>
        {
            FSMStateActor.StateEnum.VANISH,
        });
        allowedTransitions.Add(FSMStateActor.StateEnum.VANISH, new List <FSMStateActor.StateEnum>
        {
            FSMStateActor.StateEnum.NONE,
        });
        SetTransitions(allowedTransitions);
    }
    public override void Execute(ActorBehaviour _source, UnitBehaviour[] _targets)
    {
        int _baseAmount = FlatDamage;

        foreach (StatIntCouple _statDependantDamage in StatDependantDammages)
        {
            _baseAmount += _source.SourceUnit.Stats[(int)_statDependantDamage.Stat].Value * _statDependantDamage.Value / 100;
        }
        foreach (UnitBehaviour _target in _targets)
        {
            //devrait calculer en prenant en compte la défence etc, mais pas nécéssaire pour le proto
            _target.TakeDamage(_baseAmount, Type, Element, Origine);
        }
    }
Example #23
0
    public void AddBehaviour(ActorBehaviour actorBehaviour)
    {
        if (!actorBehaviours.Contains(actorBehaviour))
        {
            actorBehaviours.Add(actorBehaviour);
        }

        RefreshDictionary();

        if (!actorBehaviour.initialized)
        {
            actorBehaviour.InitializeBehaviour(this);
        }

        AssignActorReferences();
    }
Example #24
0
    void Start()
    {
        if (weapon == null)
        {
            weapon = Resources.Load <Weapon>("Data/Items/Weapons/Fists");
        }

        player        = GameManager.player;
        currentHealth = maxHealth;

        playerAnimator = player.GetComponentInChildren <Animator>();
        animator       = this.GetComponentInChildren <Animator>();

        //request UI healthbar etc
        this.GetComponent <ActorHealthbar>().Initialize(this);

        OnHealthChanged(currentHealth, maxHealth);
    }
    public override UnitBehaviour[] Execute(ActorBehaviour _source)
    {
        List <UnitBehaviour> _temporary = new List <UnitBehaviour>();

        for (int _index = 0; _index < CombatManager.Current.Teams.Count; _index++)
        {
            if (_index != _source.SourceUnit.TeamId)
            {
                foreach (UnitBehaviour _unit in CombatManager.Current.Teams[_index].FieldMembers)
                {
                    _temporary.Add(_unit);
                }
            }
        }

        UnitBehaviour[] _targets = new UnitBehaviour[1];
        return(_targets);
    }
Example #26
0
    public override void CompleteCreate()
    {
        GameObject prefab = Resources.Load(model_name) as GameObject;

        GameObject actor = MonoBehaviour.Instantiate(prefab, GetLocation(), Quaternion.Euler(mDirection)) as GameObject;

        mTarget = actor;

        //GameObject instance = Instantiate(Resources.Load("Brick", typeof(GameObject))) as GameObject;
        mActorBehaviour = actor.GetComponent <ActorBehaviour>();

        mActorBehaviour.actor = this;

        if (IsLocalPlayer())
        {
            GameObject go = GameObject.Find("Main Camera");
            if (go != null)
            {
                go.GetComponent <CompleteCameraController>().SetPlayer(actor);
            }
        }
    }
Example #27
0
    public StateMachineActor(ActorBehaviour ab)
    {
        _actorBehaviour = ab;

        var idleState       = new ActorIdleState(this, _actorBehaviour);
        var dieState        = new ActorDieState(this, _actorBehaviour);
        var vanishState     = new ActorVanishState(this, _actorBehaviour);
        var harvestState    = new ActorHarvestState(this, _actorBehaviour);
        var walkState       = new ActorWalkState(this, _actorBehaviour);
        var walkFightState  = new ActorWalkFightState(this, _actorBehaviour);
        var fightState      = new ActorFightState(this, _actorBehaviour);
        var delayFightState = new ActorDelayFightState(this, _actorBehaviour);
        var guardState      = new ActorGuardState(this, _actorBehaviour);

        var stateList = new Dictionary <StateEnum, IFsmState>
        {
            { StateEnum.IDLE, idleState },
            { StateEnum.DIE, dieState },
            { StateEnum.VANISH, vanishState },
            { StateEnum.HARVEST, harvestState },
            { StateEnum.WALK, walkState },
            { StateEnum.WALKFIGHT, walkFightState },
            { StateEnum.FIGHT, fightState },
            { StateEnum.DELAYFIGHT, delayFightState },
            { StateEnum.GUARD, guardState },
        };

        SetStates(stateList);

        var allowedTransitions = new Dictionary <StateEnum, IList <StateEnum> >();

        allowedTransitions.Add(StateEnum.IDLE, new List <StateEnum>
        {
            StateEnum.IDLE,
            StateEnum.DIE,
            StateEnum.HARVEST,
            StateEnum.WALK,
            StateEnum.WALKFIGHT,
            StateEnum.FIGHT,      // 敌人如果在附近,直接可以进入战斗状态
            StateEnum.DELAYFIGHT, // 间隔一定的时间再攻击, 弹药基数足够的情况下,第二次攻击都用此方式
            StateEnum.GUARD,
        });
        allowedTransitions.Add(StateEnum.DIE, new List <StateEnum>
        {
            StateEnum.DIE,
            StateEnum.VANISH,
        });
        allowedTransitions.Add(StateEnum.VANISH, new List <StateEnum>
        {
            StateEnum.NONE,
            StateEnum.VANISH,
        });
        allowedTransitions.Add(StateEnum.HARVEST, new List <StateEnum>
        {
            StateEnum.IDLE,
            StateEnum.DIE,
            StateEnum.WALK,
            StateEnum.WALKFIGHT,
            StateEnum.FIGHT,
            StateEnum.GUARD,
        });
        allowedTransitions.Add(StateEnum.WALK, new List <StateEnum>
        {
            StateEnum.IDLE,
            StateEnum.DIE,
            StateEnum.WALK,
            StateEnum.WALKFIGHT,
            StateEnum.FIGHT,
            StateEnum.DELAYFIGHT,
            StateEnum.GUARD,
        });
        allowedTransitions.Add(StateEnum.WALKFIGHT, new List <StateEnum>
        {
            StateEnum.IDLE,
            StateEnum.DIE,
            StateEnum.WALK,
            StateEnum.WALKFIGHT,
            StateEnum.FIGHT,
            StateEnum.DELAYFIGHT,
            StateEnum.GUARD,
        });
        allowedTransitions.Add(StateEnum.FIGHT, new List <StateEnum>
        {
            StateEnum.IDLE,
            StateEnum.DIE,
            StateEnum.WALK,
            StateEnum.WALKFIGHT,
            StateEnum.FIGHT,
            StateEnum.DELAYFIGHT,
            StateEnum.GUARD,
        });
        allowedTransitions.Add(StateEnum.DELAYFIGHT, new List <StateEnum>
        {
            StateEnum.IDLE,
            StateEnum.DIE,
            StateEnum.WALK,
            StateEnum.WALKFIGHT,
            StateEnum.FIGHT,
            StateEnum.GUARD,
        });
        allowedTransitions.Add(StateEnum.GUARD, new List <StateEnum>
        {
            StateEnum.IDLE,
            StateEnum.DIE,
            StateEnum.WALK,
            StateEnum.WALKFIGHT,
            StateEnum.FIGHT,
            StateEnum.GUARD,
        });
        SetTransitions(allowedTransitions);
    }
 public void Declare(ActorBehaviour _source)
 {
     CombatManager.Current.AddToResolveList(this, _source);
 }
 public void Execute(ActorBehaviour _source)
 {
     UnitBehaviour[] _targets = Targeting.Execute(_source);
     Effect.Execute(_source, _targets);
 }
 public static void Add(ActorBehaviour actor)
 {
     _actors.Add(actor);
 }
Example #31
0
 // Use this for initialization
 void Start()
 {
     _canvas         = GetComponent <Canvas>();
     _actorBehaviour = transform.parent.GetComponent <ActorBehaviour>();
     _freshGreen     = new Color(.3f, 1f, .13f);
 }
 // Use this for initialization
 void Start()
 {
     _actorBehaviour = transform.parent.GetComponent <ActorBehaviour>();
 }
Example #33
0
 public abstract UnitBehaviour[] Execute(ActorBehaviour _source);