public override IEnumerator Execute(GameAgent attacker, Damageable target)
    {
        while (attacking)
        {
            yield return(null);
        }
        attacking = true;

        attacker.transform.LookAt((target as DungeonObject).transform);
        attacker.playAttackAnimation();
        attacker.playAttackNoise("Melee");

        Debug.Log("Waiting for animation to finish");
        while (attacker.animating)
        {
            yield return(null);
        }

        try
        {
            target.playHitAnimation();
            target.playHitNoise("Melee");
            target.take_damage((int)(attacker.stats.DealDamage() * damageModifier));
        }
        catch (Exception e)
        {
            // swallow the error
        }

        attacking = false;
    }
Example #2
0
    public void OnInteraction(GameAgent source)
    {
        WorkTask workTask = new WorkTask();

        workTask.target = target;
        source.AddTaskToQueue(workTask);
    }
    public override IEnumerator Execute(GameAgent attacker, Damageable target)
    {
        //while (attacking) yield return null;
        attacking = true;

        attacker.transform.LookAt((target as DungeonObject).transform);
        attacker.playAttackAnimation();
        attacker.playAttackNoise("Bow");

        while (attacker.animating)
        {
            yield return(null);
        }

        var arrow = MapManager.AnimateProjectile(attacker.grid_pos, (target as DungeonObject).grid_pos, "arrow");

        while (!(arrow == null))
        {
            yield return(null);
        }

        try {
            target.playHitAnimation();
            target.playHitNoise("Bow");
            target.take_damage((int)(attacker.stats.DealDamage() * damageModifier));
        }
        catch (Exception e) {
            // swallow the error
        }

        attacking = false;
    }
 public void addAllyToPool(GameAgent ally)
 {
     if (Pos.abs_dist(ally.grid_pos, parent.grid_pos) <= MAX_REINFORCE_RANGE)
     {
         alliedPool.Add(ally);
     }
 }
Example #5
0
    private static void updatePools(GameAgent agent)
    {
        for (int j = 0; j < roster.Length; j++)
        {
            if (j == agent.team)
            {
                continue;
            }

            foreach (GameAgent enemy in roster[j])
            {
                agent.AI.addEnemyToPool(enemy);
            }
        }

        foreach (GameAgent ally in roster[agent.team])
        {
            if (ally == agent || ally.AI == null)
            {
                continue;
            }

            agent.AI.addAllyToPool(ally);
        }
    }
 public static TaskTarget GetTargetWithOwner(string taskName, GameAgent owner)
 {
     if (targets.ContainsKey(taskName))
     {
         List <TaskTarget> availableTargets = new List <TaskTarget>();
         foreach (TaskTarget target in GetTargets(taskName))
         {
             if (target.owner != owner)
             {
                 continue;
             }
             availableTargets.Add(target);
         }
         if (availableTargets.Count == 0)
         {
             return(null);
         }
         else
         {
             return(availableTargets[Random.Range(0, availableTargets.Count)]);
         }
     }
     else
     {
         return(null);
     }
 }
    public void OnInteraction(GameAgent source)
    {
        SitDownTask sitDownTask = new SitDownTask();

        sitDownTask.target = target;
        source.AddTaskToQueue(sitDownTask);
    }
    private void OnTouchUp(int fingerIndex, Vector2 fingerPos, float timeHeldDown)
    {
        if (!gameObject.activeInHierarchy || (ignoreOnPopUp && RatingAgent.GetPopUpEnabled()))
        {
            return;
        }

        if (colorController)
        {
            colorController.SetColor(ColorAgent.GetCurrentColorPack().TypeToColor(colorController.colorType));
        }

        if (GameAgent.GetWasHolding())
        {
            return;
        }

        if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, fingerPos, null))
        {
            if (OnAreaTouch != null)
            {
                OnAreaTouch();
            }

            if (OnAreaTouchWithCallback != null)
            {
                OnAreaTouchWithCallback(this);
            }

            AudioAgent.PlaySoundEffect(AudioAgent.SoundEffectType.ButtonTap);
        }
    }
    void Start()
    {
        canvas = GameObject.Find("HPBars"); //get canvas ref

        //Debug.Log("I am an upset child");
        instance = Instantiate(healthbar); //instantiate prefab
        Vector2 screenPos = Camera.main.WorldToScreenPoint(gameObject.transform.position);

        parent        = GetComponent <GameAgent>();
        bar           = instance.GetComponentInChildren <HealthBar>();
        nickname      = instance.GetComponentInChildren <Text>();
        nickname.text = parent.nickname;

        instance.transform.SetParent(canvas.transform, false); //set canvas as parent
        instance.transform.position = screenPos;

        bar.SetSliderValue(1);
        bar.SetMPSliderValue(1);

        float         barwidth     = Mathf.Min(parent.stats.maxHealth, parent.stats.maxMagicPoints, 40);
        RectTransform barTransform = instance.transform.Find("HPBar").GetComponent <RectTransform>();

        barTransform.sizeDelta = new Vector2(barwidth, 15);
        RectTransform barTransform2 = instance.transform.Find("MPBar").GetComponent <RectTransform>();

        barTransform2.sizeDelta = new Vector2(barwidth, 10);
    }
    // instantiates an agent into the map
    public GameObject instantiate(GameObject prefab, Pos pos, GameAgentStats stats = null, string name = null)
    {
        if (!IsWalkable(pos))
        {
            return(null);
        }

        GameObject clone = Instantiate(prefab, grid_to_world(pos), Quaternion.identity);
        GameAgent  agent = clone.GetComponent <GameAgent>();

        //string[] names = new string[] { "Keawa", "Benjamin", "Diana", "Jerry", "Joe" };

        if (stats == null)
        {
            agent.init_agent(pos, new GameAgentStats(CharacterRaceOptions.Human, CharacterClassOptions.Knight, 1, CharacterClassOptions.Sword), name);
        }
        else
        {
            agent.init_agent(pos, stats, name);
        }

        nav_map.removeTraversableTile(pos);
        map[pos.x, pos.y].resident = agent;
        map[pos.x, pos.y].occupied = true;
        return(clone);
    }
    public void calcReinforce()
    {
        if (state == STATE.ATTACK)
        {
            return;
        }
        if (alliedDistances == null)
        {
            return;
        }

        GameAgent mostDesireable = null;
        float     bestRating     = -1;

        for (int i = 0; i < alliedPool.Count; i++)
        {
            if (alliedDistances[i] == -1)
            {
                continue;
            }

            float rating = reinforceRating(alliedPool[i], alliedDistances[i]);
            if (rating > bestRating)
            {
                mostDesireable = alliedPool[i];
                bestRating     = rating;
            }
        }
        if (mostDesireable != null)
        {
            reinforcing = mostDesireable;
            state       = STATE.REINFORCE;
        }
    }
Example #12
0
    public void OnInteraction(GameAgent source)
    {
        DrinkWaterTask drinkWaterTask = new DrinkWaterTask();

        drinkWaterTask.target = GetComponent <TaskTarget>();
        source.AddTaskToQueue(drinkWaterTask);
    }
Example #13
0
    // Use this for initialization
    void Start()
    {
        KInt timestep = 0.25f;

        Simulator.Instance.setTimeStep(timestep);
        Simulator.Instance.SetSingleTonMode(true);
        Simulator.Instance.setAgentDefaults(15, 10, 5, 5, 2, 2, KInt2.zero);

        for (int i = 0; i < agentCount; i++)
        {
            float angle = ((float)i / agentCount) * (float)System.Math.PI * 2;

            Vector3 pos       = new Vector3((float)System.Math.Cos(angle), 0, (float)System.Math.Sin(angle)) * ringSize;
            Vector3 antipodal = -pos + goalOffset;

            int sid = Simulator.Instance.addAgent((KInt2)pos, neighborDist, maxNeighbors, timeHorizon, timeHorizonObst, radius, maxSpeed, velocity);

            if (sid >= 0)
            {
                GameObject go = LeanPool.Spawn(agentPrefab, new Vector3(pos.x, 0, pos.y), Quaternion.Euler(0, angle + 180, 0));
                go.transform.parent   = transform;
                go.transform.position = pos;
                GameAgent ga = go.GetComponent <GameAgent>();
                Assert.IsNotNull(ga);
                ga.sid = sid;
                m_agentMap.Add(sid, ga);
            }
        }

        Simulator.Instance.SetNumWorkers(0);
    }
 public void reset()
 {
     state = STATE.IDLE;
     enemyPool.Clear();
     alliedPool.Clear();
     attacking   = null;
     reinforcing = null;
     finished    = false;
 }
 public void addEnemyToPool(GameAgent enemy)
 {
     Debug.Log(enemy.grid_pos + ":" + parent.grid_pos);
     if (Pos.abs_dist(enemy.grid_pos, parent.grid_pos) <= MAX_ATTACK_RANGE)
     {
         //Debug.Log("adding to pool!");
         enemyPool.Add(enemy);
     }
 }
Example #16
0
        private static bool ReadyToTravel(GameWorld world, string currentLocation)
        {
            GameAgent player = world.AllEntities["player"];
            bool      atRest = player.S["CurrentAction"] == "resting" ? true : false;
            bool      notAtCurrentLocation = player.S["Location"] != currentLocation ? true : false;
            bool      notTravelling        = player.S["Destination"] == null ? true : false;

            return(atRest && notAtCurrentLocation && notTravelling);
        }
Example #17
0
 public void ReceiveDamage(float damageAmount, Vector3 hitPosition, GameAgent sender)
 {
     _health         -= Mathf.Clamp(_health - damageAmount, 0, 100);
     shieldPoint.text = _health.ToString();
     if (Health <= 0)
     {
         this.gameObject.SetActive(false);
     }
 }
 private static void ApplyManaPotion(Item item, GameAgent agent)
 {
     //Debug.Log("Applying MP potion!");
     agent.stats.currentMagicPoints += 20;
     agent.animator.PlayHealedAnimation();
     if (agent.stats.currentMagicPoints > agent.stats.maxMagicPoints)
     {
         agent.stats.currentMagicPoints = agent.stats.maxMagicPoints;
     }
 }
 public void removeFromRoster(GameAgent agent)
 {
     foreach (List <GameAgent> faction in teamRoster)
     {
         if (faction.Contains(agent))
         {
             faction.Remove(agent);
             return;
         }
     }
 }
 private static void ApplyHealthPotion(Item item, GameAgent agent)
 {
     //decrement item in player inventory, call HP increase func (if applicable)
     //Debug.Log("Applying HP potion!");
     agent.stats.currentHealth += 20;
     agent.animator.PlayHealedAnimation();
     if (agent.stats.currentHealth > agent.stats.maxHealth)
     {
         agent.stats.currentHealth = agent.stats.maxHealth;
     }
 }
 private float reinforceRating(GameAgent ally, int distance)
 {
     if (ally.AI.state == STATE.REINFORCE)
     {
         return((float)distance / (float)MAX_REINFORCE_RANGE);
     }
     if (ally.AI.state == STATE.ATTACK)
     {
         return((float)distance / (float)MAX_REINFORCE_RANGE + 2);
     }
     return(-1);
 }
Example #22
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            MethodInfo method = (context.ActionDescriptor as ControllerActionDescriptor).MethodInfo;

            // 如果带有游客标记则不需要做验证判断
            if (method.HasAttribute <GuestAttribute>())
            {
                return;
            }

            //#1 从Http头中得到商户信息
            bool isSite = context.HttpContext.GetAuth(out string merchant, out string secretKey);

            if (!isSite)
            {
                context.Result = (ContentResult) new Result(false, ResultStatus.SecretKey.ToString());
                return;
            }
            int  siteId = merchant.GetValue <int>();
            Site site   = SiteAgent.Instance().GetSiteInfo(siteId);

            if (site == null || site.SecretKey != secretKey)
            {
                context.Result = (ContentResult) new Result(false, ResultStatus.SecretKey.ToString());
                return;
            }

            //#2 固定参数判断(自动在游戏中创建账户)
            string gameCode = context.HttpContext.Request.Form["GameCode"];
            string userName = context.HttpContext.Request.Form["UserName"];

            if (!string.IsNullOrEmpty(gameCode))
            {
                GameSetting game = GameAgent.Instance().GetGameSetting(gameCode);
                if (game == null)
                {
                    context.Result = (ContentResult) new Result(false, ResultStatus.NoGame.ToString());
                    return;
                }
                if (!string.IsNullOrEmpty(userName))
                {
                    ResultStatus registerStatus = APIAgent.Instance().Register(siteId, userName, game, out UserGame user);
                    if (registerStatus != ResultStatus.Success)
                    {
                        context.Result = (ContentResult) new Result(false, registerStatus.ToString());
                        return;
                    }
                    context.HttpContext.SetItem(user);
                }
                context.HttpContext.SetItem(game);
            }
            context.HttpContext.SetItem(site);
        }
Example #23
0
    public Health(GameAgent agent, float maxHealth, float? startHealth = null)
    {
        this.agent = agent;
        this.maxHealth = maxHealth;

        if(startHealth.HasValue)
            currentHealth = startHealth.Value;
        else
            currentHealth = maxHealth;

        inflictions = new List<Infliction>();
    }
    public override IEnumerator Execute(GameAgent attacker, Damageable target)
    {
        while (attacking)
        {
            yield return(null);
        }
        if (attacker.stats.currentMagicPoints < 4)
        {
            yield break;
        }
        attacker.stats.currentMagicPoints = Mathf.Max((attacker.stats.currentMagicPoints - 4), 0);
        int count = attacker.stats.GetMultiHitCount();

        while (count > 0)
        {
            attacking = true;

            attacker.transform.LookAt((target as DungeonObject).transform);
            attacker.playAttackAnimation();
            attacker.playAttackNoise("Bow");

            while (attacker.animating)
            {
                yield return(null);
            }

            Projectile arrow = MapManager.AnimateProjectile(attacker.grid_pos, (target as DungeonObject).grid_pos, "arrow");

            while (!(arrow == null))
            {
                yield return(null);
            }

            try
            {
                target.playHitAnimation();
                target.playHitNoise("Bow");
                target.take_damage((int)(attacker.stats.DealDamage() * damageModifier));
            }
            catch (Exception e)
            {
                // swallow the error
            }

            // if Damageable is dead, stop loop
            // implement this


            count--;
        }
        attacking = false;
        Debug.Log("After while loop");
    }
    public GameAgentState GetGameAgentState(Pos dest)
    {
        DungeonObject obj = map[dest.x, dest.y].resident;

        if (obj == null || !(obj is GameAgent))
        {
            return(GameAgentState.Null);
        }

        GameAgent agent = obj as GameAgent;

        return(agent.stats.currentState);
    }
    void CreatAgent()
    {
        int sid = Simulator.Instance.addAgent(mousePosition);

        if (sid >= 0)
        {
            GameObject go = LeanPool.Spawn(agentPrefab, new Vector3(mousePosition.x(), 0, mousePosition.y()), Quaternion.identity);
            GameAgent  ga = go.GetComponent <GameAgent>();
            Assert.IsNotNull(ga);
            ga.sid = sid;
            m_agentMap.Add(sid, ga);
        }
    }
Example #27
0
    void Awake()
    {
        if (mInstance != null)
        {
            Debug.LogError(string.Format("Only one instance of GameAgent allowed! Destroying:" + gameObject.name + ", Other:" + mInstance.gameObject.name));
            Destroy(gameObject);
            return;
        }

        mInstance = this;

        Application.targetFrameRate = 60;
    }
Example #28
0
    void CreatAgent(Vector3 v3)
    {
        int sid = Simulator.Instance.addAgent(v3);

        if (sid >= 0)
        {
            GameObject go = LeanPool.Spawn(agentPrefab, v3, Quaternion.identity);
            GameAgent  ga = go.GetComponent <GameAgent>();
            Assert.IsNotNull(ga);
            ga.sid = sid;
            magentMap.Add(sid, ga);
        }
    }
Example #29
0
    void Awake()
    {
        if( mInstance != null )
        {
            Debug.LogError( string.Format( "Only one instance of GameAgent allowed! Destroying:" + gameObject.name +", Other:" + mInstance.gameObject.name ) );
            Destroy( gameObject );
            return;
        }

        mInstance = this;

        gesturesThisFrame = new List<GestureAgent.GestureType>();
    }
Example #30
0
    void CreatAgent()
    {
        int sid = Simulator.Instance.addAgent((KInt2)mousePosition, neighborDist, maxNeighbors, timeHorizon, timeHorizonObst, radius, maxSpeed, velocity);

        if (sid >= 0)
        {
            GameObject go = LeanPool.Spawn(agentPrefab, new Vector3(mousePosition.x, 0, mousePosition.y), Quaternion.identity);
            GameAgent  ga = go.GetComponent <GameAgent>();
            Assert.IsNotNull(ga);
            ga.sid = sid;
            m_agentMap.Add(sid, ga);
        }
    }
    public bool GetHealed(Pos dest, int healAmount)
    {
        DungeonObject obj = map[dest.x, dest.y].resident;

        if (obj == null || !(obj is GameAgent))
        {
            return(false);
        }

        GameAgent agent = obj as GameAgent;

        agent.GetHealed(healAmount);
        return(true);
    }
    //FOLLOWING METHODS FOR EQUIPMENT SYSTEM

    private static void EquipEquipment(Item item, GameAgent agent)
    {
        Debug.Log("Equipping item!");
        EquipItem equip = (EquipItem)item;
        EquipItem oldItem;

        switch (equip.type)
        {
        case EquipType.HELMET:
            oldItem = agent.inventory.helmet;
            agent.inventory.helmet = equip;
            agent.stats.attack     = (equip.atkbonus - oldItem.atkbonus);
            agent.stats.defense    = (equip.defbonus - oldItem.defbonus);
            agent.inventory.AddItem(oldItem);
            break;

        case EquipType.BOOT:
            oldItem = agent.inventory.boots;
            agent.inventory.helmet = equip;
            agent.stats.attack     = (equip.atkbonus - oldItem.atkbonus);
            agent.stats.defense    = (equip.defbonus - oldItem.defbonus);
            agent.inventory.AddItem(oldItem);
            break;

        case EquipType.ARMOR:
            oldItem = agent.inventory.armor;
            agent.inventory.helmet = equip;
            agent.stats.attack     = (equip.atkbonus - oldItem.atkbonus);
            agent.stats.defense    = (equip.defbonus - oldItem.defbonus);
            agent.inventory.AddItem(oldItem);
            break;

        case EquipType.GLOVE:
            oldItem = agent.inventory.gloves;
            agent.inventory.helmet = equip;
            agent.stats.attack     = (equip.atkbonus - oldItem.atkbonus);
            agent.stats.defense    = (equip.defbonus - oldItem.defbonus);
            agent.inventory.AddItem(oldItem);
            break;

        case EquipType.WEAPON:
            oldItem = agent.inventory.weapon;
            agent.inventory.helmet = equip;
            agent.stats.attack     = (equip.atkbonus - oldItem.atkbonus);
            agent.stats.defense    = (equip.defbonus - oldItem.defbonus);
            agent.inventory.AddItem(oldItem);
            break;
        }
    }
Example #33
0
    void Awake()
    {
        if( mInstance != null )
        {
            Debug.LogError( string.Format( "Only one instance of GameAgent allowed! Destroying:" + gameObject.name +", Other:" + mInstance.gameObject.name ) );
            return;
        }

        mInstance = this;

        //Application.targetFrameRate = 1;
    }