Example #1
0
        public bool TryMoveLivingBeingToPosition(LivingBeing lb, Vector2 targetPosition)
        {
            var retour           = false;
            var targetCellObject = this.CellOnPosition(targetPosition);

            if (null != targetCellObject)
            {
                var obstacle = this.LivingAtPosition(targetPosition);
                if (obstacle != null)
                {
                    //check politic
                    lb.Attack(obstacle);
                    retour = true;
                }
                else
                {
                    if (targetCellObject.IsWalkable(lb))
                    {
                        this.Game.MoveBeing(lb, targetPosition);
                        retour = true;
                    }
                }
            }

            return(retour);
        }
Example #2
0
        public void AutoPlay(LivingBeing lb)
        {
            var rnd = new Random();
            var ca  = rnd.Next(9);
            var dep = new Vector2(0, 0);

            switch (ca)
            {
            case 0:
                dep = new Vector2(0, 1);
                break;

            case 1:
                dep = new Vector2(1, 0);
                break;

            case 2:
                dep = new Vector2(-1, 0);
                break;

            case 3:
                dep = new Vector2(0, -1);
                break;
            }

            lb.PositionCell += dep;
        }
Example #3
0
 private void UnRegister(LivingBeing lb)
 {
     if (this.IsActivable(lb))
     {
         BlackBoard.Pool.UnRegister(lb, this.PossibleActions(lb));
     }
 }
 public void Exiting(LivingBeing lb)
 {
     if (lb.IsUserControlled)
     {
         Console.WriteLine(lb.Description + " as left");
     }
 }
Example #5
0
        private static void ProcessVisibilityWithFOV(LivingBeing being, List <List <Vector2> > listPathOfVisibility, List <MapComponent> listGameAware)
        {
            IEnumerable <MapComponent> listAtPos;

            foreach (var path in listPathOfVisibility)
            {
                var currentPos = being.PositionCell;
                foreach (Vector2 t in path)
                {
                    currentPos += t;
                    listAtPos   = listGameAware.Where(x => x.PositionCell == currentPos);
                    var stop = false;
                    foreach (var v in listAtPos)
                    {
                        v.SetColorToUse(Visibility.InView);
                        if (!v.SeenBy.Contains(being.UniqueIdentifier))
                        {
                            v.SeenBy.Add(being.UniqueIdentifier);
                        }

                        stop |= v.BlockVisibility(being);
                    }

                    if (stop)
                    {
                        break;
                    }
                }
            }
        }
 public void Entering(LivingBeing lb)
 {
     if (lb.IsUserControlled)
     {
         Console.WriteLine(lb.Description + "  as entered.");
     }
 }
Example #7
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // if list empty
            while (this.beingToPlay == null)
            {
                this.beingToPlay = BlackBoard.Scheduler.CurrentPlaying();

                if (!this.beingToPlay.IsUserControlled)
                {
                    this.beingToPlay.AutoPlay();
                    BlackBoard.Scheduler.Played();
                    this.beingToPlay = null;
                }
            }

            this.map.HandleVisibility(this.beingToPlay);
            this.keyBoardInputHandler.HandleInput(this.beingToPlay, this.poolOfAction);

            base.Update(gameTime);
        }
    public override void OnShoot(LivingBeing pShotThing)
    {
        AI tAI = pShotThing.GetComponent<AI>();
        Assert.IsNotNull(tAI, "Trying to persuade non-AI target?");

        tAI.Persuade(m_pWielder);
    }
Example #9
0
        public void Pickup(LivingBeing lb)
        {
            var listObject = this.ItemsOnPosition(lb.PositionCell).ToList();

            lb.Inventory.Poutch.AddRange(listObject);
            this.RemoveItems(listObject);
        }
Example #10
0
    void Attack(LivingBeing target)
    {
        State = AI_State.ATTACK;
        Target = target;
        TargetPos = Target.Pos;

        Animator.SetBool("Agressive", true);
    }
Example #11
0
    public override void OnShoot(LivingBeing pShotThing)
    {
        AI tAI = pShotThing.GetComponent <AI>();

        Assert.IsNotNull(tAI, "Trying to persuade non-AI target?");

        tAI.Persuade(m_pWielder);
    }
Example #12
0
        public void Register(LivingBeing lb, IEnumerable <ActionDoable> action)
        {
            if (!PossibleActions.ContainsKey(lb.UniqueIdentifier))
            {
                PossibleActions.Add(lb.UniqueIdentifier, new List <ActionDoable>());
            }

            PossibleActions[lb.UniqueIdentifier].AddRange(action);
        }
Example #13
0
    protected virtual void Awake()
    {
        Body = transform.Find("Body");
        BodyRaycastOrigin = Body.Find("BodyRaycastOrigin");

        Visual = transform.Find("Visual");
        anim   = Visual.GetComponentInChildren <Animator>();
        LB     = GetComponent <LivingBeing>();
    }
Example #14
0
 void Awake()
 {
     if (OneTimeUpdate = true)
     {
         OneTimeUpdate = !OneTimeUpdate;
     }
     livingBeing = gameObject.GetComponentInParent <LivingBeing>();
     GOSlider    = this.GetComponent <Slider>();
     GOText      = this.GetComponent <Text>();
     GOImg       = this.GetComponent <Image>();
 }
Example #15
0
 void ShowDamageText(LivingBeing obj, byte damage)
 {
     GameObject textObj = Instantiate(Text);
     textObj.GetComponent<Text>().text = damage.ToString();
     textObj.GetComponent<Text>().color = new Color(1, 1 - damage / obj.MaxHealth, 0);
     textObj.transform.SetParent(CameraCanvas);
     textObj.transform.localScale = Vector3.one;
     textObj.transform.position = new Vector2(obj.transform.position.x, obj.transform.position.y + Offset);
     StartCoroutine(MoveHelper.Fly(textObj, new Vector2(obj.transform.position.x, obj.transform.position.y + FlyHeight), FlyTime));
     textObj.AddComponent<Fader>().FadeAndDestroyObject(FadeTime);
 }
Example #16
0
        public void DropFirstObject(LivingBeing lb)
        {
            var itemToDrop = lb.Inventory.Poutch.FirstOrDefault(x => !x.IsEquipped);

            if (itemToDrop != null)
            {
                lb.Inventory.Poutch.Remove(itemToDrop);
                itemToDrop.PositionCell = lb.PositionCell;
                this.fullBoard.Add(itemToDrop);
            }
        }
        public void Equip(LivingBeing lb)
        {
            if (!this.CanEquip(lb))
            {
                throw new Exception("Can't equip");
            }

            this._isEquipped = true;
            this.whoEquipped = lb;
            lb.Statistics.ApplyBonus(this.statisModifier.StatisticDiffToApply);
        }
Example #18
0
 public GameEngine()
     : base()
 {
     this.graphics = new GraphicsDeviceManager(this);
     this.Content.RootDirectory = "Content";
     this.IsMouseVisible        = true;
     this.graphics.PreferredBackBufferHeight = 15 * SpriteSize;
     this.graphics.PreferredBackBufferWidth  = 25 * SpriteSize;
     this.beingToPlay  = null;
     this.poolOfAction = new ActionsPool();
     BlackBoard.Pool   = this.poolOfAction;
     BlackBoard.Game   = this;
 }
Example #19
0
        public void Execute(LivingBeing actor, LivingBeing target)
        {
            int damage = GodOfRandom.NumberBetween(_minDamage, _maxDamage);

            if (damage == 0)
            {
                ReportResult($"{actor.Name} missed");
            }
            else
            {
                ReportResult($"{actor.Name} hit {target.Name} for {damage}");
                target.TakeDamage(damage);
            }
        }
Example #20
0
        public void MoveBeing(LivingBeing p, Vector2 targetPosition)
        {
            BlackBoard.CurrentCamera.Move(targetPosition - p.PositionCell);
            Cell cellTarget   = this.map.fullBoard.Where <Cell>(x => x.PositionCell == targetPosition).First();
            Cell cellGoingout = this.map.fullBoard.Where <Cell>(x => x.PositionCell == p.PositionCell).First();

            cellGoingout.OnExit(p);
            p.PositionCell = targetPosition;
            cellTarget.OnEnter(p);

            // we have played, so we remove it
            BlackBoard.Scheduler.Played();
            this.beingToPlay = null;
        }
Example #21
0
        public void HandleInput(LivingBeing lb, ActionsPool poolOfAction)
        {
            this.previousKeyboardState = this.currentKeyboardState;
            this.currentKeyboardState  = Keyboard.GetState();
            var pressedKeys = this.currentKeyboardState.GetPressedKeys();

            if (pressedKeys.Except(this.previousKeyboardState.GetPressedKeys()).Any())
            {
                if (poolOfAction.ContainsAnActionFor(lb, pressedKeys))
                {
                    var action = poolOfAction.GetAction(lb, pressedKeys).Activity;
                    action(lb);
                }
            }
        }
Example #22
0
 void CheckChange(LivingBeing lb, byte unused = 0)
 {
     if (lb is Player)
     {
         float percent = (float)lb.Health / lb.MaxHealth;
         if (percent > 0.75f)
             GetComponent<Image>().sprite = FullHP;
         else if (percent > 0.5f)
             GetComponent<Image>().sprite = ThreeQuatersHP;
         else if (percent > 0.25f)
             GetComponent<Image>().sprite = HalfHP;
         else
             GetComponent<Image>().sprite = QuaterHP;
     }
 }
Example #23
0
 private static void ReitinializeVisibility(LivingBeing being, List <MapComponent> listGameAware)
 {
     Parallel.ForEach(
         listGameAware,
         element =>
     {
         if (element.SeenBy.Contains(being.UniqueIdentifier))
         {
             element.SetColorToUse(Visibility.Visited);
         }
         else
         {
             element.SetColorToUse(Visibility.Unvisited);
         }
     });
 }
        public List <ActionDoable> Activables(LivingBeing lb)
        {
            var result = new List <ActionDoable>();

            if (lb.IsUserControlled)
            {
                ActionDoable act = new ActionDoable
                {
                    Name     = "Go down",
                    Activity = (a) => a.GoMapDown(),
                    Bind     = new Keys[] { Keys.LeftShift, Keys.D }
                };
                result.Add(act);
            }

            return(result);
        }
Example #25
0
        public List <ActionDoable> Activables(LivingBeing lb)
        {
            var result = new List <ActionDoable>();

            if (lb.IsUserControlled)
            {
                var ad = new ActionDoable
                {
                    Name     = "Going upstair",
                    Activity = (a) => a.GoMapUp(),
                    Bind     = new Keys[] { Keys.LeftShift, Keys.U }
                };
                result.Add(ad);
            }

            return(result);
        }
Example #26
0
        public void ChangeMap(LivingBeing lb, bool goingDown)
        {
            var nextLVL = this.donjon.CurrentLevel + (goingDown ? 1 : -1);

            this.map.RemoveLivingBeing(lb);
            if (!lb.IsUserControlled)
            {
                throw new Exception("Error");
            }
            this.map.SetAsActive(false);
            this.donjon.CurrentLevel = nextLVL;
            this.map = this.donjon.CurrentMap;
            var targetpos = this.map.fullBoard.Where(x => x is Cell).First(x => ((Cell)x).IsWalkable(lb)).PositionCell;

            this.map.AddLivingBeing(lb, targetpos);
            this.map.SetAsActive(true);
            BlackBoard.CurrentCamera.CenterOnCell(lb.PositionCell);
            BlackBoard.CurrentMap = this.map;
        }
Example #27
0
    private IEnumerator GrowPlant(LivingBeing targetPlant, Collider targetPlantCollider)
    {
        Vector3 defaultScale = targetPlant.transform.localScale;

        targetPlant.transform.localScale = Vector3.zero;
        targetPlant.transform.position  -= Vector3.up * 0.5f * defaultScale.y;

        float t = 0;

        while (Vector3.Distance(defaultScale, targetPlant.transform.localScale) > Mathf.Epsilon)
        {
            yield return(null);

            t += _growSpeed * Time.deltaTime;
            targetPlant.transform.localScale = Vector3.Lerp(Vector3.zero, defaultScale, t);
            targetPlant.transform.position  += Vector3.up * (targetPlant.GroundYPos + 0.5f * targetPlant.transform.localScale.y - targetPlant.transform.position.y);
        }
        targetPlantCollider.enabled = true;
    }
    void Update()
    {
        if (Input.GetButtonDown("Submit"))
        {
            if (!UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
            {
                Vector3 tMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                RaycastHit Hit;

                if (Physics.Raycast(tMousePos, Camera.main.transform.forward, out Hit, float.MaxValue, Map.AllButObstaclesLayer, QueryTriggerInteraction.Ignore))
                {
                    if (Hit.collider.tag != "UI")
                    {
                        LivingBeing tLivingBeing = Hit.collider.gameObject.GetComponent <LivingBeing>();

                        if (tLivingBeing != null && !tLivingBeing.IsDead)
                        {
                            if (!tLivingBeing.IsPlayer)
                            {
                                SendTarget(tLivingBeing.gameObject);
                            }

                            else
                            {
                                SelectCharacter(Hit.collider.gameObject.GetComponent <Player>());
                            }
                        }

                        else
                        {
                            SendDestination(Hit.point);
                        }
                    }
                }
            }
        }

        if (Input.GetButton("Cancel"))
        {
            DeselectAll();
        }
    }
    public virtual void Shoot(Transform pTarget)
    {
        if (Time.fixedTime - m_fLastAttackTime >= m_fFireSpeed)
        {
            RaycastHit Hit;

            if (Physics.Linecast(m_pGun.transform.position, pTarget.transform.position, out Hit, (Map.AllButGroundLayer & LivingBeing.AllButDeadsLayer), QueryTriggerInteraction.Ignore))
            {
                LivingBeing tShotThing = Hit.collider.gameObject.GetComponent <LivingBeing>();

                if (tShotThing)
                {
                    OnShoot(tShotThing);
                }
            }

            m_fLastAttackTime = Time.fixedTime;
            m_pShootAnimation.Play();
        }
    }
Example #30
0
    private IEnumerator ChanceToGrowPlant()
    {
        while (true)
        {
            float averagePlantTime = 1f / (_plantsPerSecond + Mathf.Epsilon);
            float nextPlantTime    = Random.Range(0.8f * averagePlantTime, 1.2f * averagePlantTime);
            yield return(new WaitForSeconds(nextPlantTime));

            if (_statsManager.CanCreatePlants())
            {
                if (SuitablePositionFound())
                {
                    LivingBeing newPlant = Instantiate(_plantPrefab, _newWorldPos, Quaternion.identity);
                    newPlant.transform.parent = transform;
                    Collider newPlantCollider = newPlant.GetComponent <Collider>();
                    newPlantCollider.enabled = false;

                    StartCoroutine(GrowPlant(newPlant, newPlantCollider));
                }
            }
        }
    }
Example #31
0
        public static void HandleVisibilityOfList(LivingBeing being, List <MapComponent> listGameAware)
        {
            var currentPosition = being.PositionCell;

            // reinit visibility
            ReitinializeVisibility(being, listGameAware);

            var listPathOfVisibility = Utilitaires.GetPathsToDistanceMax(currentPosition, being.Statistics.FOV);

            // handle new visibility
            var listAtPos = listGameAware.Where(x => x.PositionCell == currentPosition);

            foreach (var v in listAtPos)
            {
                v.SetColorToUse(Visibility.InView);
                if (!v.SeenBy.Contains(being.UniqueIdentifier))
                {
                    v.SeenBy.Add(being.UniqueIdentifier);
                }
            }

            ProcessVisibilityWithFOV(being, listPathOfVisibility, listGameAware);
        }
Example #32
0
    private LivingBeing NearbyFood()
    {
        Collider[] nearbyColliders = Physics.OverlapSphere(transform.position, _animal.GetSenseRadius());

        // filter all with type _diet
        Collider[] nearbyFoodColliders =
            Array.FindAll(nearbyColliders, c => c.gameObject.GetComponent <LivingBeing>()?.GetType() == _diet);
        LivingBeing[] nearbyFood =
            Array.ConvertAll(nearbyFoodColliders, c => c.gameObject.GetComponent <LivingBeing>());

        // check which one's closer and target it
        LivingBeing closestFood  = null;
        float       smallestDist = _animal.GetSenseRadius() + 1;

        foreach (LivingBeing lb in nearbyFood)
        {
            float dist = Vector3.Distance(transform.position, lb.transform.position);
            if (dist < smallestDist && dist > Mathf.Epsilon)
            {
                if (_animal.FoodIgnored != null)
                {
                    if (_animal.FoodIgnored != lb)
                    {
                        closestFood  = lb;
                        smallestDist = dist;
                    }
                }
                else
                {
                    closestFood  = lb;
                    smallestDist = dist;
                }
            }
        }

        return(closestFood);
    }
Example #33
0
 public static void OnCreatureDeath(LivingBeing lb)//C#6.0 EBD
 {
     CreatureDied(lb);
 }
 void ExcludeLivingBeing(LivingBeing lb)
 {
     LBs.Remove(lb);
 }
Example #35
0
 public static void OnCreatureHit(LivingBeing lb, byte damage)//C#6.0 EBD
 {
     CreatureHit(lb, damage);
 }
Example #36
0
 public HitInfos(LivingBeing Attacker, PlayerAttackStats AttackStats) : this(Attacker, (AttackStats)AttackStats)
 {
     PlayerAttackStats = AttackStats;
 }
Example #37
0
    void Idle()
    {
        Target = null;
        Path.Clear();
        State = AI_State.IDLE;

        Animator.SetBool("Agressive", false);
    }
 public override void OnShoot(LivingBeing pShotThing)
 {
     pShotThing.ReceiveDamage(m_fDefaultDamages, m_pWielder);
 }
Example #39
0
    void Attack(LivingBeing target, float damage, float accuracy)
    {
        if (Random.value < accuracy)
            target.TakeDamage((byte)damage, true, true);
        else
            EventManager.OnAttackMiss(transform.position);
        RemainingMoves = 0;
        MakingTurn = false;
        EventManager.OnBluesUnrender();
        EventManager.OnLivingBeingEndTurn();

        GetComponent<SpriteRenderer>().sprite = FightingSprite;
    }
 public abstract void OnShoot(LivingBeing pShotThing);
Example #41
0
 public HitInfos(LivingBeing Attacker, EnemyAttackStats AttackStats) : this(Attacker, (AttackStats)AttackStats)
 {
     EnemyAttackStats = AttackStats;
 }
Example #42
0
 public static void OnCreatureHealed(LivingBeing lb, byte heal)//C#6.0 EBD
 {
     CreatureHealed(lb, heal);
 }