示例#1
0
文件: Session.cs 项目: liws/ETX
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            int  zone = this.DomainZone();
            long id   = this.Id;

            base.Dispose();

            this.AService.RemoveChannel(this.Id);

            foreach (RpcInfo responseCallback in this.requestCallbacks.Values.ToArray())
            {
                responseCallback.Tcs.SetException(new RpcException(this.Error, $"session dispose: {id} {this.RemoteAddress}"));
            }

            Log.Info($"session dispose: {this.RemoteAddress} zone: {zone} id: {id} ErrorCode: {this.Error}, please see ErrorCode.cs! {TimeHelper.ClientNow()}");

            this.requestCallbacks.Clear();
        }
        /// <summary>
        /// 进入触发器
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="stepPara"></param>
        /// <param name="costId"></param>
        /// <param name="cost"></param>
        /// <param name="config"></param>
        public void OnColliderIn(AOIUnitComponent from, AOIUnitComponent to, SkillStepPara stepPara, List <int> costId,
                                 List <int> cost, SkillConfig config)
        {
            var combatU = to.Parent.GetComponent <CombatUnitComponent>();

            // Log.Info("触发"+type.ToString()+to.Id+"  "+from.Id);
            // Log.Info("触发"+type.ToString()+to.Position+" Dis: "+Vector3.Distance(to.Position,from.Position));
            int formulaId = 0;//公式

            if (stepPara.Paras.Length > 1)
            {
                int.TryParse(stepPara.Paras[1].ToString(), out formulaId);
            }
            float percent = 1;//实际伤害百分比

            if (stepPara.Paras.Length > 2)
            {
                float.TryParse(stepPara.Paras[2].ToString(), out percent);
            }

            int maxNum = 0;

            if (stepPara.Paras.Length > 3)
            {
                int.TryParse(stepPara.Paras[3].ToString(), out maxNum);
            }

            if (maxNum != 0 && stepPara.Count >= maxNum)
            {
                return;                                         //超上限
            }
            stepPara.Count++;

            List <int[]> buffInfo = null;//添加的buff

            if (stepPara.Paras.Length > 4)
            {
                buffInfo = stepPara.Paras[4] as List <int[]>;
                if (buffInfo == null)
                {
                    string[] vs = stepPara.Paras[4].ToString().Split(';');
                    buffInfo = new List <int[]>();
                    for (int i = 0; i < vs.Length; i++)
                    {
                        var   data = vs[i].Split(',');
                        int[] temp = new int[data.Length];
                        for (int j = 0; j < data.Length; j++)
                        {
                            temp[j] = int.Parse(data[i]);
                        }
                        buffInfo.Add(temp);
                    }
                    stepPara.Paras[4] = buffInfo;
                }
            }

            if (buffInfo != null && buffInfo.Count > 0)
            {
                var buffC = combatU.GetComponent <BuffComponent>();

                for (int i = 0; i < buffInfo.Count; i++)
                {
                    buffC.AddBuff(buffInfo[i][0], TimeHelper.ClientNow() + buffInfo[i][1]);
                }
            }

            FormulaConfig formula = FormulaConfigCategory.Instance.Get(formulaId);

            if (formula != null)
            {
                FormulaStringFx  fx    = FormulaStringFx.GetInstance(formula.Formula);
                NumericComponent f     = from.GetParent <Unit>().GetComponent <NumericComponent>();
                NumericComponent t     = to?.GetParent <Unit>().GetComponent <NumericComponent>();
                float            value = fx.GetData(f, t);

                int realValue = (int)value;

                if (realValue != 0)
                {
                    float now = t.GetAsFloat(NumericType.HpBase);
                    Log.Info(now);
                    if (now <= realValue)
                    {
                        t.Set(NumericType.HpBase, 0);
                    }
                    else
                    {
                        t.Set(NumericType.HpBase, now - realValue);
                    }

                    EventSystem.Instance.Publish(new EventType.AfterCombatUnitGetDamage()
                    {
                        From  = from.Parent.GetComponent <CombatUnitComponent>(),
                        Unit  = combatU,
                        Value = realValue
                    });
                }
            }
        }
 protected override void Awake(SessionAcceptTimeoutComponent self)
 {
     self.Timer = TimerComponent.Instance.NewOnceTimer(TimeHelper.ServerNow() + 5000, CallbackType.SessionAcceptTimeout, self);
 }
示例#4
0
文件: Session.cs 项目: liws/ETX
 public void Send(long actorId, MemoryStream memoryStream)
 {
     this.LastSendTime = TimeHelper.ClientNow();
     this.AService.SendStream(this.Id, actorId, memoryStream);
 }
示例#5
0
        private static async ETTask <IActorResponse> CallInner(this ActorLocationSenderComponent self, ActorLocationSender actorLocationSender, int rpcId, MemoryStream memoryStream)
        {
            int  failTimes  = 0;
            long instanceId = actorLocationSender.InstanceId;

            actorLocationSender.LastSendOrRecvTime = TimeHelper.ServerNow();

            while (true)
            {
                if (actorLocationSender.ActorId == 0)
                {
                    actorLocationSender.ActorId = await LocationProxyComponent.Instance.Get(actorLocationSender.Id);

                    if (actorLocationSender.InstanceId != instanceId)
                    {
                        throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout2, $"{memoryStream.ToActorMessage()}");
                    }
                }

                if (actorLocationSender.ActorId == 0)
                {
                    IActorRequest iActorRequest = (IActorRequest)memoryStream.ToActorMessage();
                    return(ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor));
                }
                IActorResponse response = await ActorMessageSenderComponent.Instance.Call(actorLocationSender.ActorId, rpcId, memoryStream, false);

                if (actorLocationSender.InstanceId != instanceId)
                {
                    throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout3, $"{memoryStream.ToActorMessage()}");
                }

                switch (response.Error)
                {
                case ErrorCore.ERR_NotFoundActor:
                {
                    // 如果没找到Actor,重试
                    ++failTimes;
                    if (failTimes > 20)
                    {
                        Log.Debug($"actor send message fail, actorid: {actorLocationSender.Id}");
                        actorLocationSender.Error = ErrorCore.ERR_NotFoundActor;
                        // 这里不能删除actor,要让后面等待发送的消息也返回ERR_NotFoundActor,直到超时删除
                        return(response);
                    }

                    // 等待0.5s再发送
                    await TimerComponent.Instance.WaitAsync(500);

                    if (actorLocationSender.InstanceId != instanceId)
                    {
                        throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout4, $"{memoryStream.ToActorMessage()}");
                    }

                    actorLocationSender.ActorId = 0;
                    continue;
                }

                case ErrorCore.ERR_ActorTimeout:
                {
                    throw new RpcException(response.Error, $"{memoryStream.ToActorMessage()}");
                }
                }

                if (ErrorCore.IsRpcNeedThrowException(response.Error))
                {
                    throw new RpcException(response.Error, $"Message: {response.Message} Request: {memoryStream.ToActorMessage()}");
                }

                return(response);
            }
        }
示例#6
0
 public ActorMessageSender(Action <IActorResponse> callback)
 {
     this.CreateTime = TimeHelper.Now();
     this.Callback   = callback;
 }
示例#7
0
        public static void MoveForward(this MoveComponent self, bool needCancel)
        {
            Unit unit = self.GetParent <Unit>();

            long timeNow  = TimeHelper.ClientNow();
            long moveTime = timeNow - self.StartTime;

            while (true)
            {
                if (moveTime <= 0)
                {
                    return;
                }

                // 计算位置插值
                if (moveTime >= self.NeedTime)
                {
                    unit.Position = self.NextTarget;
                    if (self.TurnTime > 0)
                    {
                        unit.Rotation = self.To;
                    }
                }
                else
                {
                    // 计算位置插值
                    float amount = moveTime * 1f / self.NeedTime;
                    if (amount > 0)
                    {
                        Vector3 newPos = Vector3.Lerp(self.StartPos, self.NextTarget, amount);
                        unit.Position = newPos;
                    }

                    // 计算方向插值
                    if (self.TurnTime > 0)
                    {
                        amount = moveTime * 1f / self.TurnTime;
                        Quaternion q = Quaternion.Slerp(self.From, self.To, amount);
                        unit.Rotation = q;
                    }
                }

                moveTime -= self.NeedTime;

                // 表示这个点还没走完,等下一帧再来
                if (moveTime < 0)
                {
                    return;
                }

                // 到这里说明这个点已经走完

                // 如果是最后一个点
                if (self.N >= self.Targets.Count - 1)
                {
                    unit.Position = self.NextTarget;
                    unit.Rotation = self.To;

                    Action <bool> callback = self.Callback;
                    self.Callback = null;

                    self.Clear();
                    callback?.Invoke(!needCancel);
                    return;
                }

                self.SetNextTarget();
            }
        }
示例#8
0
 public static void StartRegainHp(this HPRegainComponent self)
 {
     self.BeStart           = true;
     self.StartMilliseconds = TimeHelper.ClientNow();
 }
示例#9
0
            protected override void Destroy(Session self)
            {
                self.AService.RemoveChannel(self.Id);

                foreach (RpcInfo responseCallback in self.requestCallbacks.Values.ToArray())
                {
                    responseCallback.Tcs.SetException(new RpcException(self.Error, $"session dispose: {self.Id} {self.RemoteAddress}"));
                }

                Log.Info($"session dispose: {self.RemoteAddress} id: {self.Id} ErrorCode: {self.Error}, please see ErrorCode.cs! {TimeHelper.ClientNow()}");

                self.requestCallbacks.Clear();
            }
示例#10
0
 public static void Send(this Session self, long actorId, MemoryStream memoryStream)
 {
     self.LastSendTime = TimeHelper.ClientNow();
     self.AService.SendStream(self.Id, actorId, memoryStream);
 }
示例#11
0
 public override void Awake(ActorLocationSender self)
 {
     self.LastSendOrRecvTime = TimeHelper.ServerNow();
     self.ActorId            = 0;
     self.Error = 0;
 }