Esempio n. 1
0
    public virtual void removeEntity(FightEntity entity)
    {
        switch (entity.type)
        {
        case ConfigConstant.ENTITY_LOOP_BEAN:
            this.beans.Remove((LoopBeanEntity)entity);
            break;

        case ConfigConstant.ENTITY_PLAYER:
            this.persons.Remove((PlayerEntity)entity);
            this.players.Remove((PlayerEntity)entity);
            break;

        case ConfigConstant.ENTITY_BULLET:
            this.bullets.Remove((BulletEntity)entity);
            break;

        case ConfigConstant.ENTITY_PRICE_BEAN:
            this.others.Remove((PriceBeanEntity)entity);
            break;

        case ConfigConstant.ENTITY_CALL:
            this.persons.Remove((CallEntity)entity);
            break;

        case ConfigConstant.ENTITY_RADISH:
            this.others.Remove((RadishEntity)entity);
            break;
        }
    }
Esempio n. 2
0
    public FightEntity GetNextEnemy(FightEntity entity)
    {
        var         entitys   = _contexts.fight.GetGroup(FightMatcher.FightRoleType);
        FightEntity enemy     = null;
        var         entityPos = entity.rolePos.pos;
        float       dis       = -1;

        foreach (var enemyEntity in entitys)
        {
            if (enemyEntity.fightRoleType.roleType != entity.fightRoleType.roleType)
            {
                if (enemy == null)
                {
                    enemy = enemyEntity;
                    dis   = Vector2.Distance(entityPos, enemyEntity.rolePos.pos);
                }
                else
                {
                    var offsetDis = Vector2.Distance(entityPos, enemyEntity.rolePos.pos);
                    if (dis < offsetDis)
                    {
                        enemy = enemyEntity;
                        dis   = offsetDis;
                    }
                }
            }
        }

        return(enemy);
    }
Esempio n. 3
0
//	void Awake () {
//		Init ();
//	}

    public void init(FightEntity entity)
    {
        this.fightEntity     = entity;
        this.clientRunTime   = (ClientRunTime)entity.map;
        this.localPositionV2 = new Vector2();
        this.localScaleV3    = new Vector3(1, 1, 1);
        this.materialList    = new List <Material> ();
        Material material;

        //一次性取出所有 MeshRenderer ParticleSystem
        Renderer[] renderers = this.GetComponentsInChildren <Renderer>();
        foreach (Renderer renderer in renderers)
        {
            material          = renderer.material;
            renderer.material = material;
            materialList.Add(material);
        }
        imageArr = this.GetComponentsInChildren <Image>();

        if (this.fightEntity.type == ConfigConstant.ENTITY_PLAYER)
        {
            Image image = Tools.FindChild2("Canvas/faceImage", this.gameObject).transform.GetChild(0).GetComponent <Image> ();
            ClientPlayerEntity player = (ClientPlayerEntity)entity;
            ResFactory.setHeadSprite(player.headUrl, image, player.uid);
            //Sprite spr = ((Player)player.view).faceSprite;
            //image.sprite = spr;
        }

        lastAlpha = 1f;
        ChangeAlpha(0);
    }
Esempio n. 4
0
    public Vector2D getHitPos(FightEntity fightEntity)
    {
        //子弹和玩家相对速度
        Vector2D deltaV = this._velocity.clone().subtract(fightEntity.velocity);
        //玩家到命中点的向量
        Vector2D deltaP = Collision.realPosition(fightEntity.position, this._position, this._map.mapData).deltaPos;
        double   a, bSQ, c, l;
        double   r   = fightEntity.shape.radius + this._shape.radius;
        double   rSQ = r * r;

        a   = deltaP.projectionOn(deltaV);
        bSQ = deltaP.lengthSQ - a * a;

        if (rSQ >= bSQ)
        {
            //体内命中,按入射位置判定
            c = Math.Sqrt(r * r - bSQ);
            l = a + c;
            //修改deltaV含义为子弹位置指向命中点向量
            deltaV.truncate(l);
            //修改deltaP含义为玩家到命中点向量
            deltaP.subtract(deltaV);
        }
        return(deltaP);
    }
Esempio n. 5
0
    /// 判断是否能够加入该策略
    public bool checkAddTactic(BaseTactic tactic)
    {
        bool        b      = false;
        FightEntity target = tactic.target;

        if (null != target)
        {
            if (this.lastTacticTargetList.IndexOf(target) >= 0)
            {
                //上次重视过的目标,这次必顶发现且更加重视
                b = true;
                tactic.cardPriority *= 1.2;
                tactic.movePriority *= 1.2;
            }
        }
        if (!b && tactic.checkDiscover())
        {
            b = tactic.checkDiscover();
        }
        if (b)
        {
            this.addTactic(tactic);
        }
        return(b);
    }
Esempio n. 6
0
    public virtual void addEntity(FightEntity entity)
    {
        switch (entity.type)
        {
        case ConfigConstant.ENTITY_LOOP_BEAN:
            this.beans.Add((LoopBeanEntity)entity);
            break;

        case ConfigConstant.ENTITY_PLAYER:
            ((PlayerEntity)entity).index = this.persons.Count;
            this.persons.Add((PlayerEntity)entity);
            this.players.Add((PlayerEntity)entity);
            break;

        case ConfigConstant.ENTITY_BULLET:
            this.bullets.Add((BulletEntity)entity);
            break;

        case ConfigConstant.ENTITY_PRICE_BEAN:
            this.others.Add((PriceBeanEntity)entity);
            break;

        case ConfigConstant.ENTITY_BARRIER:
            this.others.Add((BarrierEntity)entity);
            break;

        case ConfigConstant.ENTITY_CALL:
            this.persons.Add((CallEntity)entity);
            break;

        case ConfigConstant.ENTITY_RADISH:
            this.others.Add((RadishEntity)entity);
            break;
        }
    }
Esempio n. 7
0
    /// <summary>
    /// 有限状态机状态轮询时调用。
    /// </summary>
    /// <param name="fsm">有限状态机引用。</param>
    /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
    /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
    protected override void OnUpdate(IFsm <Monster> fsm, float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(fsm, elapseSeconds, realElapseSeconds);

        if (fsm.Owner.IsLockingAim)
        {
            FightEntity aim = fsm.Owner.LockingAim;

            if (aim != null && aim.IsDead == false)
            {
                fsm.Owner.transform.LookAt(aim.transform);
                return;
            }
        }

        if (fsm.Owner.MoveController == null)
        {
            return;
        }

        Vector3 inputVec = fsm.Owner.MoveController.GetInput();

        if (inputVec.y != 0)
        {
            /* 移动 */
            ChangeState <MonsterWalkState> (fsm);
        }
    }
Esempio n. 8
0
    public static void PerformCollision(FightEntity entity, Entity other)
    {
        if (entity == null || other == null)
        {
            return;
        }

        Bullet bullet = other as Bullet;

        if (bullet != null)
        {
            ImpactData entityImpactData = entity.GetImpactData();
            ImpactData bulletImpactData = bullet.GetImpactData();
            if (GetRelation(entityImpactData.Camp, bulletImpactData.Camp) == RelationType.Friendly)
            {
                return;
            }

            entity.ApplyDamage(bulletImpactData.Attack);

            if (bullet.SubEffectTimes())
            {
                GameEntry.Entity.HideEntity(bullet.Id);
            }
            return;
        }
    }
Esempio n. 9
0
    public void OnMoveToTarget(FightEntity entity)
    {
        var tween = transform.DOMove(LoadRolePrefabService.Instance.GetWorldPos(entity.enemyInfo.enemy), 2);

        tween.onComplete = () => {
            Debug.Log("移动完成");
        };
    }
Esempio n. 10
0
    public void addEntity(FightEntity entity)
    {
        List <FightEntity> list = this.getEntity(entity.type);

        //if (!list.Contains (entity)) {
        list.Add(entity);
        //}
    }
Esempio n. 11
0
 public override void addEntity(FightEntity entity)
 {
     base.addEntity(entity);
     if (!entity.cleared)
     {
         this.createFightObject(entity);
     }
 }
Esempio n. 12
0
    public void ReplaceEnemyInfo(FightEntity newEnemy)
    {
        var index     = FightComponentsLookup.EnemyInfo;
        var component = (EnemyInfo)CreateComponent(index, typeof(EnemyInfo));

        component.enemy = newEnemy;
        ReplaceComponent(index, component);
    }
Esempio n. 13
0
        public async Task <IActionResult> SaveFight([FromBody] FightData request)
        {
            var nameClaim = CurrentUserName;

            if (nameClaim == null)
            {
                return(Unauthorized());
            }


            if (!Guid.TryParse(request.Id, out var guid))
            {
                guid = Guid.Empty;
            }
            var fight = await _dataContext.Fights.FirstOrDefaultAsync(entity => entity.Identifier == guid).ConfigureAwait(false);

            if (fight != null)
            {
                if (fight.UserName.Trim() != nameClaim && !string.Equals(fight.UserName, "anonymous", StringComparison.OrdinalIgnoreCase))
                {
                    return(Unauthorized());
                }

                fight.Name         = request.Name;
                fight.Data         = request.Data;
                fight.IsDraft      = false;
                fight.ModifiedDate = DateTimeOffset.UtcNow;
            }
            else
            {
                fight = new FightEntity()
                {
                    Identifier   = Guid.NewGuid(),
                    Name         = request.Name,
                    UserName     = nameClaim,
                    Data         = request.Data,
                    IsDraft      = false,
                    CreateDate   = DateTimeOffset.UtcNow,
                    ModifiedDate = DateTimeOffset.UtcNow,
                    Game         = request.Game
                };
                _dataContext.Fights.Add(fight);
            }

            await _dataContext.SaveChangesAsync().ConfigureAwait(false);

            return(Json(new FightData
            {
                Id = fight.Identifier.ToString("N"),
                Name = fight.Name,
                UserName = fight.UserName,
                Data = "",
                IsDraft = fight.IsDraft.GetValueOrDefault(true),
                DateModified = fight.ModifiedDate.GetValueOrDefault(DateTimeOffset.UtcNow),
                Game = fight.Game
            }));
        }
Esempio n. 14
0
    public FightObject createFightObject(FightEntity entity)
    {
        GameObject  go          = null;
        FightObject fightObject = null;

        switch (entity.type)
        {
        case ConfigConstant.ENTITY_LOOP_BEAN:    //
            go          = ResFactory.instance.getBean(((LoopBeanEntity)entity).itemType);
            fightObject = go.GetComponent <Bean>();
            break;

        case ConfigConstant.ENTITY_PLAYER:
            if (((PlayerEntity)entity).uid == this.uid)
            {
                go          = ResFactory.createObject <GameObject>(ResFactory.instance.player);
                fightObject = go.AddComponent <PlayerSelf>();
            }
            else
            {
                go          = ResFactory.createObject <GameObject>(ResFactory.instance.player);
                fightObject = go.AddComponent <Enemy>();
            }
            break;

        case ConfigConstant.ENTITY_BULLET:
            fightObject = ResFactory.getBullet(entity.data["resId"].ToString(), this);
            break;

        case ConfigConstant.ENTITY_PRICE_BEAN:
            go          = ResFactory.instance.getBean(((PriceBeanEntity)entity).itemType);
            fightObject = go.GetComponent <Bean>();
            break;

        case ConfigConstant.ENTITY_CALL:
            go          = ResFactory.createObject <GameObject>(ResFactory.instance.call);
            fightObject = go.GetComponent <CallView>();
            break;

        case ConfigConstant.ENTITY_BARRIER:
            go          = ResFactory.loadPrefab(entity.data["resId"].ToString());
            go          = ResFactory.createObject <GameObject>(go);
            fightObject = go.GetComponent <Barrier>();
            break;

        case ConfigConstant.ENTITY_RADISH:
            go          = ResFactory.loadPrefab("radish");
            go          = ResFactory.createObject <GameObject>(go);
            fightObject = go.AddComponent <Radish>();
            break;
        }
        entity.viewData.view    = entity.view = fightObject;
        fightObject.fightEntity = entity;

        return(fightObject);
    }
Esempio n. 15
0
    public Vector2 GetWorldPos(FightEntity entity)
    {
        var parent = _heroParent;

        if (entity.fightRoleType.roleType == RoleType.ENMEY)
        {
            parent = _enemyParent;
        }

        return(parent.TransformPoint(entity.rolePos.pos));
    }
Esempio n. 16
0
 public override void clear()
 {
     this._isFinish = true;
     this.applyTarget.removeBuff(this);
     base.clear();
     this._target = null;
     this._owner  = null;
     Utils.clearObject(this.triggerAction);
     this.triggerAction = null;
     this._buffType     = null;
     this._data         = null;
 }
Esempio n. 17
0
    public override void setData(Dictionary <string, object> data)
    {
        base.setData(data);
        this._data     = (Dictionary <string, object>)data["data"];
        this._target   = (PersonEntity)this._map.getNetObject((int)(data["target"]));
        this._buffType = data["buffType"].ToString();
        this.id        = data["id"].ToString();

        this._owner     = (PersonEntity)this._map.getNetObject((int)(data["owner"]));
        this.bind       = Convert.ToBoolean(data["bind"]);
        this._operation = (int)(data["operation"]);
        this._value     = Convert.ToSingle(data["value"]);
    }
Esempio n. 18
0
 public override void clear()
 {
     Utils.clearList(this._sourcePoints);
     Utils.clearList(this._globalPoints);
     this._pivot.clear();
     this._pivot = null;
     this.position.clear();
     this.position = null;
     this._center.clear();
     this._center = null;
     this.entity  = null;
     base.clear();
 }
    /// <summary>
    /// 射线逻辑
    /// </summary>
    /// <param name="elapseSeconds"></param>
    /// <param name="realElapseSeconds"></param>
    private void RayEffectUpdate(float elapseSeconds, float realElapseSeconds)
    {
        if (isStop)
        {
            if (Time.time >= hideTime)
            {
                GameEntry.Entity.HideEntity(parentEntityId);
            }
            return;
        }
        // shootRay是碰撞射线,用于碰撞检测。1000是随便设的,让碰撞检测的射线足够长
        if (Physics.Raycast(shootRay, out shootHit, 1000))
        {
            FightEntity entity = shootHit.collider.GetComponent <FightEntity>();
            if (entity != null)
            {
                entity.ApplyDamage(bulletData.Attack);
            }
            else
            {
                isStop   = true;
                hideTime = Time.time + 0.1f;
                return;
            }

            // 因为线的长度很长(上面乘以了100),碰撞的时候需要将线最后一个坐标重新设置成碰撞点所在坐标
            int preIndex = lineRenderer.positionCount - 1;
            lineRenderer.SetPosition(preIndex, shootHit.point);

            // 达到最大效果次数,停止折射
            if (lineRenderer.positionCount > bulletEffectData.EffectTimes)
            {
                isStop   = true;
                hideTime = Time.time + 0.1f;
                return;
            }

            // 根据线的方向向量和法线,得到反射向量
            Vector3 reflectVector = Vector3.Reflect(shootRay.direction, shootHit.normal);

            // 增加一个新的点,这样线就会往折射方向延申
            lineRenderer.positionCount += 1;
            lineRenderer.SetPosition(preIndex + 1, reflectVector * 100);

            // 重新设置碰撞射线的起点和方向
            shootRay.origin    = shootHit.point;
            shootRay.direction = reflectVector;
        }
    }
Esempio n. 20
0
    ///找到某个FightObject的提示
    public EdgeHint findEdgeHint(FightEntity fightObject)
    {
        int i, len;

        len = edgeHintList.Count;
        for (i = 0; i < len; i++)
        {
            EdgeHint edgeHint = edgeHintList [i];
            if (fightObject == edgeHint.fightEntity)
            {
                return(edgeHint);
            }
        }
        return(null);
    }
Esempio n. 21
0
    public void Link(IEntity entity, Contexts contexts)
    {
        if (entity is FightEntity)
        {
            _fightEntity = entity as FightEntity;
        }
        else
        {
            Debug.Log("不是FightEntity");
            return;
        }

        _fightEntity.AddRolePosListener(this);
        _fightEntity.AddMoveToTargetListener(this);
        gameObject.Link(entity);
    }
Esempio n. 22
0
    ///移除对一个物体的边缘提示
    public void removeFightObject(FightEntity fightEntity)
    {
        int      i, len;
        EdgeHint edgeHint;

        len = edgeHintList.Count;
        for (i = 0; i < len; i++)
        {
            edgeHint = edgeHintList [i];
            if (edgeHint.fightEntity == fightEntity)
            {
                edgeHintList.RemoveAt(i);
                edgeHint.Destroy();
                return;
            }
        }
    }
Esempio n. 23
0
    ///复活后重开
    public void reset()
    {
        this.tacticsCount = 0;
        this.moveAimPosition.copy(this._aiPlayer.player.position);
        this.steeringV2d.zero();
        this.moveAimAngle      = this._aiPlayer.player.angle;
        this.moveAimSpeedScale = 0;

        this.steeringHp     = this._aiPlayer.IQ;
        this.lastAngleSpeed = 0;
        this.dodgeTarget    = null;

        //遗忘上一次考虑过的战术
        this.lastTacticTargetList.Clear();

        this.resetTacticsCD(0.1);
        this.resetCardCD(0.1);
    }
Esempio n. 24
0
    /// 增加对一个物体的边缘提示
    public void addFightObject(int index, FightEntity fightEntity)
    {
        GameObject go = this.getEdgeHintGameObject(index);

        go.SetActive(false);
        go.transform.SetParent(this.gameObject.transform, false);

        EdgeHint edgeHint = go.GetComponent <EdgeHint> ();

        //edgeHint.name = prefabs[index].name +" "+fightEntity.view.name;
        edgeHint.init(fightEntity);
        if (index == INDEX_RADISH)
        {
            radishEdgeHint = edgeHint;
        }
        edgeHintList.Add(edgeHint);
//		ViewUtils.setGameObjectScale (go, 12f);
    }
    /// <summary>
    /// 有限状态机状态轮询时调用。
    /// </summary>
    /// <param name="fsm">有限状态机引用。</param>
    /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
    /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
    protected override void OnUpdate(IFsm <Monster> fsm, float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(fsm, elapseSeconds, realElapseSeconds);

        if (fsm.Owner.IsLockingAim)
        {
            FightEntity aim = fsm.Owner.LockingAim;

            if (aim != null && aim.IsDead == false)
            {
                fsm.Owner.transform.LookAt(aim.transform);

                // 除非敌人离开了自己的攻击范围,否则,在锁定目标的过程中,不进行移动(避免不断和敌人靠近,直至重合)
                float distance = AIUtility.GetDistance(fsm.Owner, aim);
                if (fsm.Owner.CheckInAtkRange(distance) == false)
                {
                    fsm.Owner.Forward(elapseSeconds);
                }

                return;
            }
        }

        if (fsm.Owner.MoveController == null)
        {
            return;
        }

        Vector3 inputVec = fsm.Owner.MoveController.GetInput();

        if (inputVec.y != 0)
        {
            // 移动
            fsm.Owner.Forward(inputVec.y * elapseSeconds);
        }
        else
        {
            // 站立
            ChangeState <MonsterIdleState> (fsm);
        }
    }
Esempio n. 26
0
    public void OnAnyLoadPrefabPaht(FightEntity entity, string path)
    {
        Transform parent;

        if (entity.fightRoleType.roleType == RoleType.HERO)
        {
            parent = _heroParent;
        }
        else
        {
            parent = _enemyParent;
        }

        GameObject go      = Resources.Load <GameObject>(path);
        var        fightGo = GameObject.Instantiate(go, parent);

        fightGo.GetComponent <CharacterFlip>().enabled  = false;
        fightGo.GetComponent <WeaponControls>().enabled = false;
        var view = fightGo.GetComponent <FightView>();

        view.Link(entity, _contexts);
    }
Esempio n. 27
0
    private void checkCollision()
    {
        if (this._joystickForce.length <= 0.2f)
        {
            return;
        }

        //检查碰撞 提前给召唤物转向。
        Vector2D v = Vector2D.createVector2(this.getProperty(ConfigConstant.PROPERTY_JOYSTICK_MAX) * 3f, this._angle);

        this._fakeShape.radius = this._shape.radius * 3;
        this._fakeShape.position.copy(v.add(this._position));
        v.clear();
        Vector2D vv = this._joystickForce.clone();
        //绕过障碍物和人。
        List <FightEntity> entitys = this._map.getFightEntitysByRange(this._fakeShape, new List <int> {
            ConfigConstant.ENTITY_BARRIER, ConfigConstant.ENTITY_PLAYER
        }, null, -1);

        for (int i = 0, len = entitys.Count; i < len; i++)
        {
            FightEntity entity = entitys[i];
            if (entity == this.seekTarget)
            {
                continue;
            }
            int      dir         = entity.findDelta.sign(vv);
            Vector2D v2          = dir < 0 ? vv.reverse().perp : vv.perp;
            double   overlapRate = ((this._fakeShape.radius + entity.shape.radius) - entity.findDist) / entity.findDist;
            v2.length = Math.Min(overlapRate * 0.5f, 0.5f);//越近给的转向力越大。
            this._joystickForce.add(v2);
            this._joystickForce.truncate(1f);
            v2.length = overlapRate * 10f;//越近给的转向力越大。
            //v2.length = 5f;//越近给的转向力越大。
            this.addForce(v2);
            v2.clear();
        }
        vv.clear();
    }
Esempio n. 28
0
    public Buff initBuff(string id, string buffType, PersonEntity target, FightEntity owner, Dictionary <string, object> data)
    {
        this.id        = id;
        this._data     = data;
        this._target   = target;
        this._buffType = buffType;
        this._owner    = owner;

        this.bind = !this._data.ContainsKey("time");

        this._totalTime = this._data.ContainsKey("time") ? (int)(this._data["time"]) : int.MaxValue;
        if (this._data.ContainsKey("interval"))
        {
            this._interval = (int)(this._data["interval"]);
        }
        if (this._data.ContainsKey("operation"))
        {
            this._operation = (int)(data["operation"]);
        }
        if (this._data.ContainsKey("skill"))
        {
            this.triggerAction = new TriggerAction(this._map).initTrigger(this._interval, this._totalTime, (Dictionary <string, object>) this._data, this.applyTarget);
            this.triggerAction.start();
        }

        if (this._data.ContainsKey("value"))
        {
            this._value = this._buffType == ConfigConstant.PROPERTY_ASP && this._operation <= 2?
                          Math2.angleToRadian(Convert.ToSingle(data["value"])) :
                          Convert.ToSingle(data["value"]);
        }
        //作用在谁的身上。
        this.applyTarget.addBuff(this);

        this.applyBuff();
        this._intervalHandler = this.onIntervalHandler;
        return(this);
    }
Esempio n. 29
0
    public List <FightEntity> getFightEntitysByGrids(List <Grid> grids, List <int> types)
    {
        this.helpEntity.Clear();
        List <FightEntity> result = this.helpEntity;

        for (int i = 0, len = grids.Count; i < len; i++)
        {
            for (int j = 0, len2 = types.Count; j < len2; j++)
            {
                int type = types[j];
                List <FightEntity> entitys = grids[i].getEntity(type);
                for (int k = 0, len3 = entitys.Count; k < len3; k++)
                {
                    FightEntity entity = entitys[k];
                    if (entity.alived && !result.Contains(entity))
                    {
                        result.Add(entity);
                    }
                }
            }
        }
        return(result);
    }
Esempio n. 30
0
    public static GeomBase createGeom(FightEntity entity, object[] datas, object[] offset = null)
    {
        GeomBase result = null;

        switch (datas.Length)
        {
        case 1:
            result = new GeomCircle(entity.map);
            break;

        case 2:
            result = new GeomRect(entity.map);
            break;

        case 3:
        case 4:
            result = new GeomSector(entity.map);
            break;
        }
        result.entity = entity;
        result.parseData(datas, offset);
        return(result);
    }