//--------------------------------------------------- // DataUpdate //--------------------------------------------------- bool DataUpdate() { List <CharacterModel.Data> playerList = GetTeamCharacterDataList(TEAM_TYPE.PLAYER); for (int i = 0; i < _oldHpList.Count; i++) { HpData hpData = _oldHpList[i]; foreach (CharacterModel.Data playerData in playerList) { if (hpData.ActorId == playerData.ActorId) { if (hpData.OldHp != playerData.Hp && playerData.Hp <= 0) { DieCallBack(playerData.ActorId); } else if (hpData.OldHp != playerData.Hp) { DamageCallBack(playerData.ActorId); } hpData.OldHp = playerData.Hp; _oldHpList[i] = hpData; break; } } } return(true); }
// HP 통지 정보 수신 함수. public void OnReceiveHitPointPacket(int node, PacketId id, byte[] data) { HitPointPacket packet = new HitPointPacket(data); HpData hpData = packet.GetPacket(); //Debug.Log("[CLIENT] Receive hitpoint packet:" + hpData.characterId); chrBehaviorBase behavior = findCharacter <chrBehaviorBase>(hpData.characterId); if (behavior == null) { return; } chrController controller = behavior.control; if (controller == null) { return; } if (controller.global_index < 0) { return; } //string log = "[CLIENT] Set HP:" + hpData.characterId + " HP:" + hpData.hp; //Debug.Log(log); // 캐릭터의 HP 반영. controller.setHitPoint(hpData.hp); }
public CharacterObject(Transform transform, GameDefine.Camp camp) : base(transform) { m_Camp = camp; m_HpData = new HpData(GameDefine.CharacterObjectMaxHp, GameDefine.CharacterObjectMaxHp, camp); m_UIHp = App.manager.uiMgr.CreateUI <UIHpViewController>(UIRegister.UIHp, transform, new Vector3(0, 36, 0)); m_UIHp.SetData(m_HpData); }
public void ChangeHurt(GameDefine.Camp camp, float value) { int targetIndex = -1; for (int index = 0; index < m_CurHurtCount; index++) { if (m_HurtCamps[index] == camp) { targetIndex = index; break; } } if (targetIndex == -1) { m_CurHurtCount += 1; targetIndex += 1; m_HurtCamps[targetIndex] = camp; m_HurtDict[targetIndex] = new HpData(m_MaxHp, value, camp); } else { m_HurtDict[targetIndex].ChangeCurHp(value); } int minIndex = -1; float minValue = m_MaxHp; for (int index = 0; index < m_CurHurtCount; index++) { if (index != targetIndex) { if (minValue > m_HurtDict[index].m_CurHp) { minValue = m_HurtDict[index].m_CurHp; minIndex = index; } } } float changeCurHp = 0; if (minIndex != -1) { if (m_HurtDict[minIndex].m_CurHp < value) { changeCurHp = value - m_HurtDict[minIndex].m_CurHp; } m_HurtDict[minIndex].ChangeCurHp(-value); } if (m_CurHurtCount == 1) { changeCurHp = -value; } ChangeCurHp(changeCurHp); }
// public bool Serialize(HpData packet) { bool ret = true; ret &= Serialize(packet.characterId, HpData.characterNameLength); ret &= Serialize(packet.hp); return(ret); }
//==================================================== public void SendHitPointData(int charId, float hpData) { if (network != null) { HpData data = new HpData(); data.characterId = charId; data.hp = hpData; HitPointPacket packet = new HitPointPacket(data); network.SendUnreliableToAll <HpData>(packet); } }
//====================================================== public void OnReceiveHitPointPacket(int node, PacketId id, byte[] data) { // 패킷 수신 HitPointPacket packet = new HitPointPacket(data); HpData hpData = packet.GetPacket(); // 송신한 플레이어 구별 GameObject netplayer = findPlayer(hpData.characterId); // 캐릭터 hp 감소 netplayer.GetComponent <NetPlayerCtrl>().hp = hpData.hp; }
public void NotifyHitPoint(string charId, float hp) { if (m_network != null) { // 패킷 데이터 작성. HpData data = new HpData(); data.characterId = charId; data.hp = hp; // 캐릭터 좌표 송신. HitPointPacket packet = new HitPointPacket(data); m_network.SendReliableToAll <HpData>(packet); } }
// public bool Deserialize(ref HpData element) { if (GetDataSize() == 0) { // 데이터가 설정되어 있지 않습니다. return(false); } bool ret = true; ret &= Deserialize(ref element.characterId, HpData.characterNameLength); ret &= Deserialize(ref element.hp); return(ret); }
// public bool Deserialize(ref HpData element) { if (GetDataSize() == 0) { // 데이터가 설정되지 않았다. return(false); } bool ret = true; ret &= Deserialize(ref element.characterId); ret &= Deserialize(ref element.hp); return(ret); }
//==================================================== public void SendHitPointData(int charId, float hpData) { if(network != null) { HpData data = new HpData(); data.characterId = charId; data.hp = hpData; HitPointPacket packet = new HitPointPacket(data); network.SendUnreliableToAll<HpData>(packet); } }
public void UpdateHp(long nowTime) { System.Console.WriteLine("Now UpdateHp."); int n = TestParameters2.nTpsl; if (m_simuStrategy != null) { SimulationData.Instance.OnNewData(nowTime); } var dt = Feng.Data.DbHelper.Instance.ExecuteDataTable( string.Format("SELECT TIME FROM {0}_M1 WHERE TIME NOT IN (SELECT TIME FROM {0}_HP) AND TIME <= {1} AND TIME > {2} AND {3}", m_symbol, nowTime, nowTime - 60 * 60 * 24 * 7, string.IsNullOrEmpty(TestParameters.DbSelectWhere) ? "1 = 1" : TestParameters.DbSelectWhere)); var txn = Feng.Data.DbHelper.Instance.BeginTransaction(); foreach (System.Data.DataRow row in dt.Rows) { long time = (long)row["Time"]; var newHpSql = new SqlCommand(string.Format("IF NOT EXISTS (SELECT * FROM [{0}_HP] WHERE Time = {1}) INSERT INTO [{0}_HP] ([Time],[hp],[hp_date],[IsComplete]) VALUES ({1}, @hp, @hp_date, 0)", m_symbol, time)); sbyte?[, ,] hps = new sbyte?[Parameters.AllDealTypes.Length, TestParameters2.CandidateParameter.BatchTps.Length, TestParameters2.CandidateParameter.BatchSls.Length]; long?[, ,] hpTimes = new long?[Parameters.AllDealTypes.Length, TestParameters2.CandidateParameter.BatchTps.Length, TestParameters2.CandidateParameter.BatchSls.Length]; for (int k = 0; k < Parameters.AllDealTypes.Length; ++k) { for (int i = 0; i < TestParameters2.CandidateParameter.BatchTps.Length; ++i) { for (int j = 0; j < TestParameters2.CandidateParameter.BatchSls.Length; ++j) { hps[k, i, j] = null; hpTimes[k, i, j] = null; } } } newHpSql.Parameters.AddWithValue("@hp", HpData.SerializeHp(hps)); newHpSql.Parameters.AddWithValue("@hp_date", HpData.SerializeHpTimes(hpTimes)); newHpSql.Transaction = txn as SqlTransaction; Feng.Data.DbHelper.Instance.ExecuteNonQuery(newHpSql); } try { Feng.Data.DbHelper.Instance.CommitTransaction(txn); } catch (Exception) { Feng.Data.DbHelper.Instance.RollbackTransaction(txn); throw; } dt = Feng.Data.DbHelper.Instance.ExecuteDataTable(string.Format("SELECT * FROM {0}_HP WHERE TIME <= {1} AND IsComplete = 0", m_symbol, nowTime)); txn = Feng.Data.DbHelper.Instance.BeginTransaction(); foreach (System.Data.DataRow row in dt.Rows) { if (m_simuStrategy == null) { InitSimulationStrategys(); } long time = (long)row["Time"]; DateTime date = WekaUtils.GetDateFromTime(time); sbyte?[, ,] hps = HpData.DeserializeHp((byte[])row["hp"]); long?[, ,] hpTimes = HpData.DeserializeHpTimes((byte[])row["hp_date"]); if (date.Minute == 0 && date.Hour == 12) { System.Console.WriteLine(string.Format("Now updatehp of {0}, {1}", date.ToString(Parameters.DateTimeFormat), m_symbol)); } bool[] isComplete = new bool[Parameters.AllDealTypes.Length]; for (int k = 0; k < Parameters.AllDealTypes.Length; ++k) { isComplete[k] = true; char dealType = Parameters.AllDealTypes[k]; for (int i = 0; i < TestParameters2.CandidateParameter.BatchTps.Length; ++i) { if (!isComplete[k]) { break; } //if (i % n != n - 1) // continue; for (int j = 0; j < TestParameters2.CandidateParameter.BatchSls.Length; ++j) { if (!isComplete[k]) { break; } //if (j % n != n - 1) // continue; if (hps[k, i, j].HasValue && hps[k, i, j].Value != -1) { continue; } ISimulateStrategy strategy = m_simuStrategy[i, j]; //if (j == 5 && i == 9 && date == new DateTime(2010, 6, 1, 0, 15, 0)) //{ //} DateTime?closeDate; bool? hp; if (dealType == 'B') { hp = strategy.DoBuy(date, -1, out closeDate); } else if (dealType == 'S') { hp = strategy.DoSell(date, -1, out closeDate); } else { throw new ArgumentException("Invalid dealtype of " + dealType); } if (hp.HasValue) { //WekaUtils.Instance.WriteLog(string.Format("Get Update Result of {0},{1},{2},{3} = {4},{5}", // time, dealType, // TestParameters.DefaultCandidateParameter.BatchTps[i], TestParameters.DefaultCandidateParameter.BatchSls[j], // hp.Value, closeDate.Value)); if (hp.Value) { // tp for (int jj = j; jj < TestParameters2.CandidateParameter.BatchSls.Length; ++jj) { hps[k, i, jj] = 1; hpTimes[k, i, jj] = WekaUtils.GetTimeFromDate(closeDate.Value); } } else { for (int ii = i; ii < TestParameters2.CandidateParameter.BatchTps.Length; ++ii) { hps[k, ii, j] = 0; hpTimes[k, ii, j] = WekaUtils.GetTimeFromDate(closeDate.Value); } } } else { isComplete[k] = false; break; } } } } System.Data.SqlClient.SqlCommand updateCmd = new SqlCommand(string.Format("UPDATE [{0}_HP] SET [hp] = @hp,[hp_date] = @hp_date,[IsComplete] = @IsComplete WHERE [Time] = @Time", m_symbol)); updateCmd.Parameters.AddWithValue("@hp", HpData.SerializeHp(hps)); updateCmd.Parameters.AddWithValue("@hp_date", HpData.SerializeHpTimes(hpTimes)); updateCmd.Parameters.AddWithValue("@IsComplete", WekaUtils.AndAll(isComplete)); updateCmd.Parameters.AddWithValue("@Time", time); updateCmd.Transaction = txn as SqlTransaction; Feng.Data.DbHelper.Instance.ExecuteNonQuery(updateCmd); } try { Feng.Data.DbHelper.Instance.CommitTransaction(txn); } catch (Exception) { Feng.Data.DbHelper.Instance.RollbackTransaction(txn); throw; } }
public void SetData(HpData hpData) { m_HpData = hpData; m_BgImage.color = GameDefine.CampColor[m_HpData.m_Camp]; UpdateOtherColor(); }