public List <Grid> getGrids(GeomBase geom, List <Grid> grids = null) { if (null == grids) { this.helpGrids.Clear(); grids = this.helpGrids; } if (geom.radius <= 0) { return(grids); } if (geom.applyEntity) { geom.position.copy(geom.entity.position); geom.angle = geom.entity.angle; } geom.updatePoints(); Vector2D positon = geom.position; int radius = geom.radius; int startX = (int)((positon.x - radius) / this.size); int endX = (int)((positon.x + radius) / this.size); int startY = (int)Math.Max(0, (positon.y - radius) / this.size); int endY = (int)Math.Min((positon.y + radius) / this.size, this.rowNum - 1); for (int i = startX; i <= endX; i++) { for (int j = startY; j <= endY; j++) { Grid grid = this.getGrid(i, j); grids.Add(grid); } } return(grids); }
public override void initConfig(Dictionary <string, object> data = null) { this.teamIndex = (int)(data["teamIndex"]); this.shipId = data["shipId"].ToString(); this.uid = data["uid"].ToString(); this.name = null == data["name"] ? this.uid : data["name"].ToString(); this.level = 1; //(data["level"]==null)?1:(int)data["level"]; this.ownerPlayer = this; this.id = "player"; this.headUrl = this.uid.IndexOf("-") == 0 ? this.name : data["head"] == null ? "" : ((Dictionary <string, object>)data["head"])["use"].ToString(); this.fightResult = new FightResult(this._map); this.fightResult.init(); this.cardGroup = new CardGroupAction(this._map); this.partGroup = new PartGroupAction(this._map); this.cardGroup.ids = new List <object>((object[])data["cardGroup"]).ConvertAll <Dictionary <string, object> >((object obj) => { return((Dictionary <string, object>)obj); }); this.cardGroup.init(this); this.partGroup.init(this); base.initConfig((Dictionary <string, object>)DataManager.inst.beckon[this.id]); this._attractShape = Collision.createGeom(this, new object[] { (int)this.getProperty(ConfigConstant.PROPERTY_ATTRACT) }); this.actionManager.addAction(this.cardGroup); this.actionManager.addAction(this.partGroup); this.updateLevel(); }
public override void setData(Dictionary <string, object> data) { this._oldPosition.setXY(-1, -1); base.setData(data); this.velocityLimitMax = (int)(data["velocityLimitMax"]); this._position = Vector2D.createVector4((Dictionary <string, object>)data["position"]); this.birthPosition = Vector2D.createVector4((Dictionary <string, object>)data["birthposition"]); this._velocity = Vector2D.createVector4((Dictionary <string, object>)data["velocity"]); this._shape = (GeomBase)this._map.getNetObject((int)(data["shape"])); this._netId = (int)(data["netId"]); this.id = data["id"].ToString(); if (data.ContainsKey("ownerPlayer")) { this.ownerPlayer = (PlayerEntity)this._map.getNetObject((int)(data["ownerPlayer"])); } this._angle = Convert.ToDouble(data["angle"]); this._alived = Convert.ToBoolean(data["alived"]); this._data = (Dictionary <string, object>)data["data"]; this.setNewViewData(); this.generateGrids();//这之前 shape必须初始化完毕! if (this.view == null) { ((ClientRunTime)this._map).createFightObject(this); } else { this.view.reset(); } this._scale = Convert.ToDouble(data["scale"]); if (this._data.ContainsKey("birthAreaGrid")) { this._birthAreaGrid = (int)(this._data["birthAreaGrid"]); } }
private static CollisionInfo rectToRect(GeomBase geom1, GeomBase geom2) { GeomRect rect1 = (GeomRect)geom1; GeomRect rect2 = (GeomRect)geom2; Vector2D centerDistanceVertor = rect1.center.clone().subtract(rect2.center); Vector2D[] axes = new Vector2D[] { rect1.axisX, rect1.axisY, rect2.axisX, rect2.axisY, }; help.isHit = true; for (int i = 0, len = axes.Length; i < len; i++) { if (rect1.getProjectionRadius(axes[i]) + rect2.getProjectionRadius(axes[i]) <= Math.Abs(centerDistanceVertor.dotProd(axes[i]))) { help.isHit = false; break; } } centerDistanceVertor.clear(); return(help); }
private static CollisionInfo circleToCircle(GeomBase geom1, GeomBase geom2) { help.dist = geom1.position.dist(geom2.position); help.overlap = help.dist - (geom1.radius + geom2.radius); help.isHit = help.overlap < 0; return(help); }
private static CollisionInfo circleToLine(GeomBase geom1, GeomBase geom2) { GeomCircle circle = (GeomCircle)geom1; GeomLine line = (GeomLine)geom2; Vector2D v1 = circle.center.clone().subtract(line.point1); Vector2D v2 = line.vector2D; double len = v2.length; v2.normalize(); double u = v1.dotProd(v2); Vector2D v0 = Vector2D.createVector(); if (u <= 0) { v0.copy(line.point1); } else if (u >= len) { v0.copy(line.point2); } else { v0.copy(v2.multiply(u).add(line.point1)); } help.isHit = v0.dist(circle.center) <= circle.radius; v0.clear(); v1.clear(); v2.clear(); return(help); }
public override void setData(Dictionary <string, object> data) { this.uid = data["uid"].ToString(); if (this.uid == ((ClientRunTime)this._map).uid) { ((ClientRunTime)this._map).localPlayer = (ClientPlayerEntity)this; } this.cardGroup = (CardGroupAction)this._map.getNetObject((int)(data["cardGroup"])); this.partGroup = (PartGroupAction)this._map.getNetObject((int)(data["partGroup"])); this.shipId = data["shipId"].ToString(); this.index = (int)(data["index"]); this.name = data["name"].ToString(); if (data.ContainsKey("reviveAction")) { this.reviveAction = (TimeAction)this._map.getNetObject((int)(data["reviveAction"])); this.reviveAction.callBack = this.revive; } this.teamIndex = (int)(data["teamIndex"]); this.calls = new List <object>((object[])data["calls"]).ConvertAll <CallEntity>((object netId) => { return((CallEntity)this._map.getNetObject((int)(netId))); }); this.fightResult = (FightResult)this._map.getNetObject((int)(data["fightResult"])); this._attractShape = (GeomBase)this._map.getNetObject((int)(data["attractShape"])); this.headUrl = data["headUrl"].ToString(); base.setData(data); }
public override void setData(Dictionary <string, object> data) { this.reliveTime = (TimeAction)this._map.getNetObject((int)data["reliveTime"]); this.reliveTime.callBack = this.reliveHandler; this._seek = (GeomBase)this._map.getNetObject((int)data["seek"]); this.teamIndex = (int)data["teamIndex"]; this._buffs = new List <object>((object[])data["buffs"]).ConvertAll <Buff>((object id) => { return((Buff)this._map.getNetObject((int)id)); }); base.setData(data); }
public override void clear() { this.dispatchEventWith(EventConstant.DEAD); base.clear(); Utils.clearObject(this._seekShape); Utils.clearObject(this._hitShape); this._seekShape = null; this._hitShape = null; this.target = null; }
///取得其他玩家,Biggo添加 public List <PlayerEntity> findPlayer(GeomBase geom, int aim = 1, int sort = 0, bool checkCollision = true) { Func <FightEntity, FightEntity, bool> filter = this.getAimFilter(aim); List <int> types = new List <int> { ConfigConstant.ENTITY_PLAYER }; List <FightEntity> players = this.getFightEntitysByRange(geom, types, filter, sort, checkCollision); return(players.ConvertAll <PlayerEntity>((e) => { return e as PlayerEntity; })); }
public override void clear() { base.clear(); this.shallow = null; Utils.clearObject(this.seekRange); this.seekRange = null; this.lockTarget = null; this.seekTarget = null; this.seekData = null; this.owner = null; }
public override void initConfig(Dictionary <string, object> data = null) { this.id = "radish"; this._shape = Collision.createGeom(this, new object[] { (int)(data["radius"]) }); this.birthPosition = this._position = Vector2D.createVector(0, this._map.mapData.heightHalf); base.initConfig(data); this._seek = Collision.createGeom(this, new object[] { ConfigConstant.ATTRACT }); this.reliveTime = new TimeAction(this._map).init(ConfigConstant.RADISH_RADISH_START_TIME, this.reliveHandler); this._buffs = new List <Buff>(); }
/// 这个里面的entitys 会被复用的 所以 取出来人物的时候 如果 里面还要调用此方法的话,请使用副本。 public List <FightEntity> getFightEntitysByRange(GeomBase shape, List <int> types, Func <FightEntity, FightEntity, bool> filter = null, int sort = 0, bool checkCollision = true) { List <FightEntity> entitys = this.getFightEntitysByGrids(this.getGrids(shape), types); for (int i = entitys.Count - 1; i >= 0; i--) { //直接过滤就不用检测碰撞了! //Biggo修改 if ((filter != null && !filter(shape.entity, entitys[i]))) { entitys.RemoveAt(i); } else if (checkCollision) { CollisionInfo info = Collision.checkCollision(shape, entitys[i].shape, this.map.mapData); if (info.isHit) { entitys[i].findDist = info.dist; entitys[i].findDelta.copy(info.deltaPos); } else { entitys.RemoveAt(i); } } } switch (sort) { case 0: entitys.Sort((e1, e2) => { double dist1 = e1.findDist; double dist2 = e2.findDist; //这个是否要传递一个deltaPos 还是要传递一个距离? 还是两个都要传。 e1.findDist = dist1; e2.findDist = dist2; if (dist1 - dist2 < 0) { return(-1); } else if (dist1 - dist2 > 0) { return(1); } else { return(e1.netId - e2.netId); } }); break; } return(entitys); }
public void init() { this.findEnemyPlayerList = new List <PlayerEntity>(); this.findEnemyPersonList = new List <PersonEntity>(); this.findAllyPlayerList = new List <PlayerEntity>(); this.findAllyPersonList = new List <PersonEntity>(); this.findBulletList = new List <BulletEntity>(); this.findBeanList = new List <BeanEntity>(); // Collision.createGeom(this, new object[] { (int)this.getProperty(ConfigConstant.PROPERTY_ATTRACT) this._radarShape = Collision.createGeom(this._aiPlayer.player, (new object[] { 1 })); this.reset(); }
public List <PersonEntity> getPerson(GeomBase geom, int aim = 1, int sort = 0, bool call = true, bool checkCollision = true) { //Biggo修改 Func <FightEntity, FightEntity, bool> filter = this.getAimFilter(aim); List <int> types = call ? new List <int> { ConfigConstant.ENTITY_PLAYER, ConfigConstant.ENTITY_CALL } : new List <int> { ConfigConstant.ENTITY_PLAYER }; List <FightEntity> persons = this.getFightEntitysByRange(geom, types, filter, sort, checkCollision); //把FightEntity类型 转化成personEntity类型。 return(persons.ConvertAll <PersonEntity>((e) => { return e as PersonEntity; })); }
private static CollisionInfo circleToSector(GeomBase geom1, GeomBase geom2) { GeomCircle circle = (GeomCircle)geom1; GeomSector sector = (GeomSector)geom2; GeomLine line1 = sector.line1; GeomLine line2 = sector.line2; //这个因为有需求所以就这么直接写一下了。 bool result = !(0 != sector.inRadius && sector.center.dist(circle.center) <= sector.inRadius /* + circle.radius*/) && //不能在内圆 ((line1.checkPoint(circle.center) >= 0 && line2.checkPoint(circle.center) <= 0) || //在夹角内 circleToLine(circle, line1).isHit || circleToLine(circle, line2).isHit); //或者与线相交 help.isHit = result; return(help); }
protected virtual void useSkill() { List <PersonEntity> targets = null; if (this._triggerData.ContainsKey("condition")) { Dictionary <string, object> condition = (Dictionary <string, object>) this._triggerData["condition"]; GeomBase geom = Collision.createGeom(this._person, (object[])condition["range"], (object[])condition["offset"]); if (condition.ContainsKey("offsetType") && (int)condition["offsetType"] != 0) { geom.applyEntity = false; geom.position.copy(this._person.position); geom.angle = this._person.angle; Vector2D v = this._person.getVertexPosition((int)condition["offsetType"]).clone(); v.angle += this._person.angle; geom.position.add(v); v.clear(); } targets = this._person.map.getPerson(geom, (int)(condition["aim"]), (int)(condition["sort"])); Utils.clearObject(geom); if (0 == targets.Count) { return; //有条件 查找不到人就return。 } if (null != this.lockTarget) //锁定了人 并且能查找到人。并且能在攻击范围内使用技能 { if (!targets.Contains(this.lockTarget)) { return; } } else //一开始没有锁定人 { this.lockTarget = targets[0]; } } SkillAction skillAction = new SkillAction(this._map).init((Dictionary <string, object>) this._triggerData["skill"], this._person, this.lockTarget); this._person.addAction(skillAction); //skillAction.start(); if (this.breakGroup && null != skillAction.lockTarget) { this.breakAction.cannel(); } this._cdTime.reset(); }
public override TriggerAction initTrigger(int interval, int totalTime, Dictionary <string, object> triggerData, PersonEntity player, PersonEntity lockTarget) { base.initTrigger(interval, totalTime, triggerData, player, lockTarget); Dictionary <string, object> skillData = this.skillData; Dictionary <string, object> shapeData = (Dictionary <string, object>)skillData["seek"]; this._seekShape = Collision.createGeom(this._person, (object[])shapeData["range"], (object[])shapeData["offset"]); shapeData = (Dictionary <string, object>)skillData["hit"]; this._hitShape = Collision.createGeom(this._person, (object[])shapeData["range"], (object[])shapeData["offset"]); this._maxHitCount = (int)(skillData["count"]); this._deepA = Convert.ToDouble(skillData["deepA"]); this._deepB = Convert.ToDouble(skillData["deepB"]); this._person.map.specialAction(this); return(this); }
public override void setData(Dictionary <string, object> data) { base.setData(data); this._seekShape = (GeomBase)this._map.getNetObject((int)(data["seekShape"])); this._hitShape = (GeomBase)this._map.getNetObject((int)(data["hitShape"])); if (data.ContainsKey("target")) { this.target = (PersonEntity)this._map.getNetObject((int)(data["target"])); } this._maxHitCount = (int)(data["maxHitCount"]); this._deepA = Convert.ToDouble(data["deepA"]); this._deepB = Convert.ToDouble(data["deepB"]); this.hitCount = (int)(data["hitCount"]); }
public override void setData(Dictionary <string, object> data) { Dictionary <string, object> property = (Dictionary <string, object>)data["property"]; /***************************************************************/ foreach (string key in property.Keys) { this._property[key] = Convert.ToDouble(property[key]); } /***************************************************************/ property = (Dictionary <string, object>)data["helpProperty"]; foreach (string key in property.Keys) { this._helpProperty[key] = Convert.ToDouble(property[key]); } /***************************************************************/ this._propertyChange = Convert.ToBoolean(data["propertyChange"]); this.actionManager = (ActionManager)this._map.getNetObject((int)(data["actionManager"])); this._force = Vector2D.createVector4((Dictionary <string, object>)data["force"]); this.hp = (int)(data["hp"]); this.level = (int)(data["level"]); this._joystickForce = Vector2D.createVector4((Dictionary <string, object>)data["joystickForce"]); this._steeringForce = Vector2D.createVector4((Dictionary <string, object>)data["steeringForce"]); this._dead = Convert.ToBoolean(data["dead"]); this._buffs = new List <object>((object[])data["buffs"]).ConvertAll <Buff>((object netId) => { return((Buff)this._map.getNetObject((int)(netId))); }); this.skillManager = (SkillManager)this._map.getNetObject((int)(data["skillManager"])); this._collisionShape = (GeomBase)this._map.getNetObject((int)(data["collisionShape"])); //重新组织buffMap this._buffMap.Clear(); for (int i = 0, len = this._buffs.Count; i < len; i++) { string buffId = this._buffs[i].id; if (!this._buffMap.ContainsKey(buffId)) { this._buffMap[buffId] = new List <Buff>(); } this._buffMap[buffId].Add(this._buffs[i]); } base.setData(data); }
private static CollisionInfo circleToRect(GeomBase geom1, GeomBase geom2) { GeomCircle circle = (GeomCircle)geom1; GeomRect rect = (GeomRect)geom2; Vector2D unRotated = circle.center.clone().subtract(rect.center); unRotated.angle -= rect.angle; unRotated = unRotated.add(rect.center); Vector2D closest = Vector2D.createVector(); if (unRotated.x < rect.x) { closest.x = rect.x; } else if (unRotated.x > rect.right) { closest.x = rect.right; } else { closest.x = unRotated.x; } if (unRotated.y < rect.y) { closest.y = rect.y; } else if (unRotated.y > rect.bottom) { closest.y = rect.bottom; } else { closest.y = unRotated.y; } help.isHit = unRotated.dist(closest) < circle.radius; unRotated.clear(); closest.clear(); return(help); }
public override void clear() { this._dead = true; this._property = null; this._helpProperty = null; Utils.clearObject(this._collisionShape); Utils.clearObject(this.skillManager); Utils.clearObject(this.actionManager); Utils.clearObject(this._force); Utils.clearObject(this._joystickForce); Utils.clearObject(this._steeringForce); Utils.clearList(this._buffs); this._collisionShape = null; this.skillManager = null; this.actionManager = null; this._force = null; this._joystickForce = null; this._steeringForce = null; base.clear(); }
public static CollisionInfo checkCollision(GeomBase geom1, GeomBase geom2, MapData mapData) { //把大的放在前面! if (geom1.type > geom2.type) { GeomBase temp = geom1; geom1 = geom2; geom2 = temp; } if (geom1.applyEntity) { geom1.position.copy(geom1.entity.position); geom1.angle = geom1.entity.angle; } if (geom2.applyEntity) { geom2.position.copy(geom2.entity.position); geom2.angle = geom2.entity.angle; } CollisionInfo result = realPosition(geom1.position, geom2.position, mapData); geom1.position.copy(result.pos1); geom2.position.copy(result.pos2); geom1.updatePoints(); geom2.updatePoints(); int type = geom1.type | geom2.type; result = handlerMap[1](geom1, geom2); //非圆形 就再判断一次! if (result.isHit && type != 1) { result = handlerMap[type](geom1, geom2); } return(result); }
public override void setData(Dictionary <string, object> data) { this._seekRange = (GeomBase)this._map.getNetObject((int)(data["seekRange"])); this._lifeTime = (TimeAction)this._map.getNetObject((int)(data["lifeTime"])); this._seekData = (Dictionary <string, object>)(data["seekData"]); if (data.ContainsKey("seekTarget")) { this.seekTarget = (PersonEntity)this._map.getNetObject((int)(data["seekTarget"])); } this._attackRange = (GeomBase)this._map.getNetObject((int)(data["attackRange"])); this._attackData = (Dictionary <string, object>)(data["attackData"]); if (data.ContainsKey("attackAction")) { this._attackAction = (MagicSkillAction)this._map.getNetObject((int)(data["attackAction"])); } this._fakeShape = (GeomBase)this._map.getNetObject((int)(data["fakeShape"])); this.index = (int)data["index"]; this._layer = (int)data["layer"]; this.offset = Vector2D.createVector4((Dictionary <string, object>)data["offset"]); base.setData(data); }
public override void initConfig(Dictionary <string, object> data = null) { Dictionary <string, object> personConfig = (Dictionary <string, object>)data["property"]; //TODO:这里根据成长等级 计算! personConfig = (Dictionary <string, object>)Utils.clone(personConfig); foreach (string property in ConfigConstant.PROPERTY_ARRAY) { if (personConfig.ContainsKey(property)) { double value = -1; switch (property) { case ConfigConstant.PROPERTY_ASP: value = Math2.angleToRadian(Convert.ToDouble(personConfig[property])); break; default: value = Convert.ToDouble(personConfig[property]); break; } this._helpProperty[property] = this._property[property] = value; } } this.hp = (int)(this._property[ConfigConstant.PROPERTY_HP]); this._shape = Collision.createGeom(this, (new object[] { personConfig[ConfigConstant.PROPERTY_RADIUS] })); this._collisionShape = Collision.createGeom(this, (new object[] { personConfig[ConfigConstant.PROPERTY_COLLISION_RADIUS] })); base.initConfig(data); this.actionManager = new ActionManager(this._map); this.skillManager = new SkillManager(this._map); this.actionManager.addAction(this.skillManager); this.actionManager.start(); }
public override void initConfig(Dictionary <string, object> data = null) { //this.scale = 0.5; this.level = (int)data["base_level"]; this.id = data["name"].ToString(); data = (Dictionary <string, object>)DataManager.inst.beckon[this.id]; this._seekData = (Dictionary <string, object>)data["seekCondition"]; this._seekRange = Collision.createGeom(this.ownerPlayer, (object[])this._seekData["range"], (object[])this._seekData["offset"]); this._seekRadius = this._seekRange.radius; this._attackData = (Dictionary <string, object>)data["attackCondition"]; this._attackRange = Collision.createGeom(this, (object[])this._attackData["range"], (object[])this._attackData["offset"]); this._position = Vector2D.createVector2(600, this.ownerPlayer.angle + Math.PI).add(this.ownerPlayer.position); this._lifeTime = new TimeAction(this._map).init((int)data["time"]); base.initConfig(data); this._fakeShape = Collision.createGeom(this, (new object[] { this._shape.radius * 3 })); this._fakeShape.applyEntity = false; this._attackRange.applyEntity = false; this._angle = this.ownerPlayer.angle; this.ownerPlayer.addCallEntity(this); this._joystickForce.length = 1; }
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); }
public List <PersonEntity> getPerson(GeomBase geom, int aim = 1, int sort = 0, bool call = true, bool checkCollision = true) { return(this.findEntity.getPerson(geom, aim, sort, call, checkCollision)); }
///取得其他玩家,Biggo添加 public List <PlayerEntity> findPlayer(GeomBase geom, int aim = 1, int sort = 0, bool checkCollision = true) { return(this.findEntity.findPlayer(geom, aim, sort, checkCollision)); }
/// 这个里面的entitys 会被复用的 所以 取出来人物的时候 如果 里面还要调用此方法的话,请使用副本。 public List <FightEntity> getFightEntitysByRange(GeomBase shape, List <int> types, Func <FightEntity, FightEntity, bool> filter = null, int sort = 0, bool checkCollision = true) { return(this.findEntity.getFightEntitysByRange(shape, types, filter, sort, checkCollision)); }