public void onShootBallOut(FBActor actor, FixVector3 velocity, Fix64 angle, FixVector3 target) { //jlx2017.05.26-log:因为行为树也要使用这个消息,所以使用fire,而不使用fire2Rendering LogicEvent.fire("onShootBallOut", actor.id); fbGame.generateRenderAction <RAL.BallShootAction>(actor.id, actor.shootingType, velocity.toVector3(), (float)angle, target.toVector3()); }
void playEnemyDefiance(ActorView enemy) { LogicEvent.fire("onPlayTaunt", enemy.id); var self = SceneViews.instance.getCurFBScene().getMainActor(); around(enemy, self); }
public void LogicStart() { LogicEvent.fire("onFBGameStart"); fbWorld.world.resetFrame(); aiWorld.reset(); changeState(GameState.Ready); }
public FBGame newFBGame() { fbGame = new FBGame(); LogicEvent.fire("onFBGameNewed"); return(fbGame); }
public static void doDone(BallCollidedWallAction actionObject) { #if ARTIEST_MODE LogicEvent.fire("editor_onBallHit", actionObject.point); #else var ball = SceneViews.instance.getCurFBScene().ball; //jlx2017.07.05-log:这里加负号是为了将墙的法线反向 ball.hitWall(actionObject.point, -actionObject.normal, actionObject.kickerElement); ball.setRotateType(actionObject.velocity); #endif }
public static void doDone(BallPassAction actionObject) { #if ARTIEST_MODE var scene = SceneViews.instance.getCurFBScene(); var actor = scene.getActor(actionObject.objectID); LogicEvent.fire("editor_onActorPassBallOut", actor); #else //SceneViews.instance.getCurFBScene().ball.showTrail(true); #endif var scene = SceneViews.instance.getCurFBScene(); scene.getActor(actionObject.objectID).pass(); scene.ball.pass(); scene.ball.setRotateType(actionObject.velocity); }
//请求焦点 public override void requestFocus(ActorView actor) { base.requestFocus(actor); SkinnedMeshRenderer smr = actor.GetComponentInChildren <SkinnedMeshRenderer>(); if (smr != null) { smr.material.SetColor("_Switch", new Color(0.0f, 1.0f, 0.0f, 1.0f)); } LogicEvent.fire("lerpSkillColor", 1.0f); LogicEvent.fire2Lua("onChangeNameBindPoint", actor.id, actor.getWaistPoint(), 0, actor.height); }
//释放焦点 public override void releaseFocus(ActorView actor) { base.releaseFocus(actor); SkinnedMeshRenderer smr = actor.GetComponent <SkinnedMeshRenderer>(); if (smr != null) { smr.material.SetColor("_Switch", new Color(1.0f, 0.0f, 0.0f, 1.0f)); } LogicEvent.fire("resetSkillColor", 1.0f); LogicEvent.fire2Lua("onChangeNameBindPoint", actor.id, actor.transform, -0.3f, actor.height * 1.5f); }
void loadServerMessages() { if (fbGame != null) { fbGame.destory(); fbGame = null; } //byte[] data = ResourcesManager.instance.getFileData(serverMessagesName); byte[] data = ConfigResourceLoader.inst.getFileData(serverMessagesName); BytesStream stream = new BytesStream(data); serverMessages.Clear(); var tsn = new TableStartNotify(); tsn.unMarshal(stream); //tsn.unserialize(stream); fbGame = new FBGame(); LogicEvent.fire("onFBGameNewed", fbGame); fbGame.setupFBGame(tsn.tableId, tsn.mapId); fbGame.createCoach(string.Format("{0}/Resources/Config/Behaviac", UnityEngine.Application.dataPath)); //创建玩家 var playerCount = tsn.allPlayerInfos.Count; for (int i = 0; i < playerCount; ++i) { var player = tsn.allPlayerInfos[i]; fbGame.createPlayer(0, player.frameId, player.roleId, player.team, "给我来段FreeStyle", false, player.ai); } //处理输入消息 var fm = new FramesMsg(); fm.unMarshal(stream); //fm.unserialize(stream); for (int i = 0; i < fm.allFrameMessages.Count; ++i) { var msg = fm.allFrameMessages[i]; pushServerMessage(msg); } fbGame.changeState(GameState.Ready); }
void playSelfDefiance(ActorView self) { var targetPosition = calculateOffsetPosition(self, cameraCtrl.config.showActorOffset); lookAtTime = cameraCtrl.config.showSelfMoveTime; cameraCtrl.transform.DOMove(targetPosition, cameraCtrl.config.showSelfMoveTime) .SetDelay(cameraCtrl.config.aroundStayTime) .OnStart(() => { curLookAtPosition = self.getCenterPosition(); lookAtTweener = cameraCtrl.transform.DOLookAt(curLookAtPosition, lookAtTime); }) .OnComplete(() => { lookAtTweener.Kill(); lookAtTweener = null; LogicEvent.fire("onPlayTaunt", self.id); }); }
void Start() { initLuaBridge(); LogicEvent.add("on_ProtoMsgParse", this, "on_ProtoMsgParse"); LogicEvent.add("on_BinMsgParse", this, "on_BinaryMsgParse"); LogicEvent.add("on_LuaEvent", this, "on_LuaEvent"); Zeus.inst.setRawMsgProc((msgID, msgName, msgBuf) => { var msgInfo = MsgDef.inst.getMsgByID(msgID); if (msgInfo.msgType != MsgType.protobuf) { return; } LogicEvent.fire("on_ProtoMsgParse", msgName, msgBuf); }); }
public override void enter() { game.onFBGameEnter(); game.changeCampState(game.goalTeam); game.resetPosition(); game.playersAITakeOver(true); game.fbWorld.setEnableBT(true); game.onEnableRecordInput(false); if (WithoutEnterShow_4Test_EditorOnly.instance != null) { LogicEvent.fire2Lua("onEnterShowFinished", (int)game.mainActorTeam); LogicEvent.fire("onWaitForSync"); subState = SubState.WaitForSync; } else { subState = SubState.Wait; } }
public override void execute(Fix64 deltaTime) { base.execute(deltaTime); switch (subState) { case SubState.Wait: if (timer < game.fbWorld.config.showEnemyMoment) { return; } var enemys = game.fbWorld.getEnemys(game.mainActorTeam, false); if (enemys != null && enemys.Count > 0) { var randomIdx = (int)(enemys.Count * (float)game.fbWorld.randomUnit); if (randomIdx >= enemys.Count) { randomIdx = enemys.Count - 1; } var randomEnemy = enemys[randomIdx]; LogicEvent.fire2Rendering("onShowEnemy", randomEnemy.id); } subState = SubState.ShowEnemy; return; case SubState.ShowEnemy: if (timer < game.fbWorld.config.enterShowTime) { return; } LogicEvent.fire2Lua("onEnterShowFinished", (int)game.mainActorTeam); LogicEvent.fire("onWaitForSync"); subState = SubState.WaitForSync; return; case SubState.WaitForSync: return; } }
public void onFBGameEnter() { LogicEvent.fire("onFBGameEnter"); }
public static void doDone(ProfilerAction actionObject) { LogicEvent.fire("onPingActionDone", actionObject.stamp); }
public void onFBGameDestroyed() { LogicEvent.fire("onFBGameDestroyed"); }
public void onFBGameCreated() { LogicEvent.fire("onFBGameCreated"); }
void doorKeeperCathingBall(FBActor shooter, FBActor actor) { //球的轨迹和守门员的交点 FixVector2 intersectPoint = FixVector2.kZero; Fix64 intersectHeight = Fix64.One; Fix64 ballFlyTime = Fix64.Zero; bool canHit = ball.estimateHit(actor.direction, -FixVector2.dot(actor.getPosition(), actor.direction), out ballFlyTime, out intersectPoint, out intersectHeight); if (!canHit) { Debuger.Log("Can not fly to doorkeeper"); return; } #if UNITY_EDITOR LogicEvent.fire("onDoorKeeperCatchingBallView", actor, intersectPoint, intersectHeight); #endif FixVector2 toward = intersectPoint - actor.getPosition(); Fix64 distance = toward.length; int cathingZoneIndex = -1; if (distance < actor.configuration.dkcb_edgeLimit[0]) { if (intersectHeight < actor.configuration.dkcb_edgeLimit[1]) { //a区 cathingZoneIndex = 0; } else if (intersectHeight < actor.configuration.dkcb_edgeLimit[2]) { //b区 cathingZoneIndex = 1; } else if (intersectHeight < actor.configuration.dkcb_edgeLimit[3]) { //c区 cathingZoneIndex = 2; } else { //H区,直接返回,不处理 cathingZoneIndex = -1; } } else if (distance < actor.configuration.dkcb_edgeLimit[6]) { if (intersectHeight < actor.configuration.dkcb_edgeLimit[4]) { //fe区 cathingZoneIndex = 4; } else if (intersectHeight < actor.configuration.dkcb_edgeLimit[5]) { //gd区 cathingZoneIndex = 3; } else { cathingZoneIndex = -1; } } else { //H区,直接返回,不处理 cathingZoneIndex = -1; } bool pretendCatchingBall = false; if ((cathingZoneIndex == 3 || cathingZoneIndex == 4)) { //修改获取球的区域 Fix64 rightDoorV = shooter.team == FBTeam.kBlue ? new Fix64(1) : new Fix64(-1); FixVector2 doorPosition = new FixVector2(config.worldSize.x * rightDoorV, Fix64.Zero); Fix64 s = (shooter.getPosition() - doorPosition).length; if (s > shooter.configuration.maxGoalDistance) { s = shooter.configuration.maxGoalDistance; } Fix64 shootRate = ConstTable.ShootBall_GoalRate[(int)shooter.shootingType] * ball.getEnergy().goalRate *((Fix64)1.0f - s / shooter.configuration.maxGoalDistance); //失误计算 Fix64 randV = this.randomUnit; pretendCatchingBall = randV >= shootRate; Debuger.Log("ShootBall GoalRate:" + (float)shootRate + " random:" + (float)randV); if (pretendCatchingBall) { if (cathingZoneIndex == 3) { intersectHeight -= ConstTable.GoallKeeperPretendGetBallMissDistance; if (intersectHeight < actor.configuration.dkcb_edgeLimit[4]) { cathingZoneIndex = 4; } } if (cathingZoneIndex == 4) { intersectHeight += ConstTable.GoallKeeperPretendGetBallMissDistance; if (intersectHeight > actor.configuration.dkcb_edgeLimit[4]) { cathingZoneIndex = 3; } } } } if (cathingZoneIndex != -1) { actor.doCathingGoalBall(new FixVector2(intersectPoint.x, intersectPoint.y), intersectHeight, ballFlyTime, cathingZoneIndex, pretendCatchingBall); } }
//检测是否可以停到球 public static bool checkCatchingBall(FBActor actor) { if (actor.world.ball.owner != null || actor.world.ball.willBeCatched) { return(false); } //球速度不能为0也不能太大 var ballSquareSpeed = actor.world.ball.particleVelocity.squareLength; if (ballSquareSpeed == Fix64.Zero || ballSquareSpeed > actor.configuration.scb_maxBallSpeed.square) { //Debuger.Log("Speed too big " + (float)ballSquareSpeed); return(false); } //球员速度不能太快 if (actor.particle.velocity.squareLength > actor.configuration.scb_maxActorSpeed.square) { //Debuger.Log("Actor too quick to get ball" + (float)actor.particle.velocity.squareLength); return(false); } //求出足球方向和检测半径是否有交点 Fix64 ballSpeedLength = actor.world.ball.particleVelocity.length; FixVector2 ballActor = actor.world.ball.getPosition() - actor.getPosition(); Fix64 dot = FixVector2.dot(-ballActor, actor.world.ball.particleVelocity / ballSpeedLength); //方向相反 if (dot <= Fix64.Zero) { //Debuger.Log("Negative Direction to getBall" + (float)ballActor.length); return(false); } Fix64 d2 = ballActor.squareLength - dot.square; //无交点 if (d2 > actor.configuration.scb_maxRadius) { //Debuger.Log("no intersect point" + (float)ballActor.length); return(false); } Fix64 b2 = actor.configuration.scb_maxRadius.square - d2; if (b2 <= Fix64.Zero) { //Debuger.Log("D1"); return(false); } Fix64 s = dot - Fix64.Sqrt(b2); if (s < Fix64.Zero) { //Debuger.Log("Ball in Range???" + (float)ballActor.length); return(false); } FixVector2 normalizedBallActor = ballActor.normalized; FixVector2 bIntersectPoint = actor.world.ball.getPosition() + s * actor.world.ball.particleVelocity.normalized; #if UNITY_EDITOR LogicEvent.fire("setIntersectPoint", bIntersectPoint); #endif Fix64 t = Fix64.Zero; Fix64 dampingAcceleration = Fix64.Zero; bool canReachPoint = actor.world.ball.estimate(bIntersectPoint, out t, out dampingAcceleration); if (!canReachPoint) { //Debuger.Log("Can not read Point"); return(false); } if (t >= actor.configuration.scb_maxCathingTime) { //Debuger.Log("t > scb_maxCathingTime distance:" + (float)ballActor.length); return(false); } //弹跳次数>1不处理 EstimateHeightInfo heightInfo = actor.world.ball.estimateHeight(t); if (heightInfo.landedTimes > 0) { //Debuger.Log("heightInfo.landedTimes > 0"); return(false); } //脚下停球 if (heightInfo.destHeight <= actor.configuration.scb_catchingHeightLimit[0]) { ////动画时间太短 //if (t < actor.configuration.scb_catchingAniTime[0]) //{ // Debuger.Log("t < actor.configuration.scb_catchingAniTime :t=" + (float)t); // return false; //} //Debuger.Log("StandCatchingBall begin"); FixVector2 faceTo = (bIntersectPoint - actor.getPosition()).normalized; FixVector2 target = actor.getPosition() + faceTo * actor.configuration.scb_catchingOffset[0]; actor.world.ball.willCatchFreeBall(actor, target, t, actor.configuration.scb_catchingOffsetH[0], Fix64.FastAbs(dampingAcceleration)); actor.m_stateVector = faceTo; actor.m_stateValue = t; actor.m_nextState = StandCatchingBall.instance; return(true); } for (int i = 1; i < actor.configuration.scb_catchingHeightLimit.Length; ++i) { if (heightInfo.destHeight > actor.configuration.scb_catchingHeightLimit[i - 1] && heightInfo.destHeight <= actor.configuration.scb_catchingHeightLimit[i] ) { //if (t < actor.configuration.scb_catchingAniTime[i]) //{ // Debuger.Log("Air Cathing ball can not procced moveTime:t" + (float)t + " aniTime:" + (float)actor.configuration.scb_catchingAniTime[i]); // return false; //} FixVector2 cPoint = actor.getPosition() + actor.configuration.scb_catchingOffset[i] * ballActor.normalized; actor.world.ball.willCatchFreeBall(actor, cPoint, t, actor.configuration.scb_catchingOffsetH[i], Fix64.FastAbs(dampingAcceleration)); actor.m_stateVector = normalizedBallActor; actor.m_stateValue = t; actor.m_stateDataIndex = i; actor.m_nextState = AirCatchingBall.instance; return(true); } } //Debuger.Log("can not get ball heightInfo.destHeight" + (float)heightInfo.destHeight); return(false); }
public void onOwnerAttached(FBActor owner) { //UnityEngine.Debug.LogError("onOwnerAttached fire onChangeCampState " + owner.team); LogicEvent.fire("onChangeCampState", owner.team); fbGame.generateRenderAction <RAL.BallAttachAction>(owner.id, owner.isDoorKeeper()); }
public FBActor findTarget(FBActor src, FixVector2 direction, int index, int teamMask, FBActor exclude) { Fix64 maxRadius = src.configuration.passBallMaxR[index]; Fix64 minRadius = src.configuration.passBallMinR[index]; Fix64 theta = src.configuration.passBallFov[index]; Fix64 bestRadius = m_ball.owner.configuration.passBallBestR[index]; if (theta <= Fix64.Zero) { return(null); } var cosTheta = Fix64.Cos(theta); List <FBActor> preferTargets = new List <FBActor>(); var actorCount = m_actors.Count; for (int i = 0; i < actorCount; i++) { var actor = m_actors[i]; if (actor == exclude || ((int)actor.team & teamMask) == 0) { continue; } var d = actor.particle.position - src.getPosition(); var len = d.length; if (len < minRadius || len > maxRadius) { continue; } var cos = Fix64.Zero; if (len == Fix64.Zero) { cos = Fix64.One; } else { cos = FixVector2.dot(d.normalized, direction); } if (cos < cosTheta) { continue; } preferTargets.Add(actor); } FixVector2 preferPoint = src.getPosition() + direction * bestRadius; preferTargets.Sort(new FBActorTargetFindCompare(preferPoint)); FBActor destTarget = null; for (int i = 0; i < preferTargets.Count; ++i) { if (checkBlocked(src, preferTargets[i])) { continue; } destTarget = preferTargets[i]; break; } #if UNITY_EDITOR LogicEvent.fire("onMainCharacterPassingBall", src, direction, index, destTarget, preferTargets); #endif return(destTarget); }