void SkipTurn() { MDebug.Log("^ai skip turn"); m_unit.SkipTurn(); }
IEnumerator AttackOrMove() { MDebug.Log("What to do..`?"); UnitAction_ApplyEffectFromWeapon attack = getAttack(); UnitAction_Move move = getMove(); //dictionary of all units and the paths by which they are attackable Dictionary <Unit, List <List <Tile> > > attack_map = GetPathMapForTargets(); MDebug.Log("^aiAttack Map Count:" + attack_map.Count); List <Unit> units_attackable = Unit.GetAllUnitsOfOwner(0, false).Where(unit => attack.CanTarget(unit)).ToList(); MDebug.Log("^aiAttackable " + units_attackable.Count); List <Unit> units_move_attackable = attack_map.Where(kvp => CanFinishPathInMoves(1, kvp.Value)).Select(kvp => kvp.Key).ToList(); List <Unit> units_movable = attack_map.Where(kvp => !units_move_attackable.Contains(kvp.Key)).Select(kvp => kvp.Key).ToList(); if (attack_map.Count > 0 && (preferred_target == null || !preferred_target.IsActive)) { preferred_target = M_Math.GetRandomObject(attack_map.Select(kvp => kvp.Key).ToList()); } if (preferred_target == null) { yield return(StartCoroutine(MoveRandom())); yield break; } if (!units_attackable.Contains(preferred_target) && (!units_attackable.IsNullOrEmpty() && (!attack_map.ContainsKey(preferred_target) || M_Math.Roll(Constants.AI_TARGET_SWITCH_WHEN_OUT_OF_ATTACK_RANGE)))) { MDebug.Log("^ainew Prefferred from" + units_attackable.Count); preferred_target = M_Math.GetRandomObject(units_attackable); } if (attack.CanTarget(preferred_target) && units_attackable.Contains(preferred_target)) { Tile better_pos = GetReachableAttackPosition(preferred_target); if (m_Actions.HasAP(2) && better_pos != null) { yield return(StartCoroutine(Move(better_pos))); yield break; } else { yield return(StartCoroutine(Attack(preferred_target))); yield break; } } else { List <Unit> other_move_targets = units_move_attackable.Where(unit => unit != preferred_target && !units_attackable.Contains(unit)).ToList(); if (!other_move_targets.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_ATTACK_MOVE_WHEN_OUT_OF_MOVE_ATTACK_RANGE)) { preferred_target = M_Math.GetRandomObject(other_move_targets); } else { if (!attack_map.ContainsKey(preferred_target) && !units_movable.IsNullOrEmpty() && M_Math.Roll(Constants.AI_TARGET_SWITCH_TO_CHASE_WHEN_OUT_OF_ATTACK_RANGE)) { preferred_target = M_Math.GetRandomObject(units_movable); } } if (attack_map.ContainsKey(preferred_target)) { if (units_move_attackable.Contains(preferred_target)) { Tile attack_pos = GetReachableAttackPosition(preferred_target); if (attack_pos != null) { yield return(StartCoroutine(Move(attack_pos))); } else { yield return(StartCoroutine(MoveRandom())); } yield break; } else { Tile Final_Target_Tile = GetBestAttackPosition(preferred_target, attack_map[preferred_target].Select(path => path[path.Count - 1]).ToList()); List <Tile> final_path = TileManager.Instance.FindPath(m_unit.currentTile, Final_Target_Tile, m_unit); Tile target = move.GetFurthestMovibleTileOnPath(final_path); yield return(StartCoroutine(Move(target))); yield break; } } else { yield return(StartCoroutine(MoveRandom( ))); yield break; } } }
private void SaveSummaryToFile() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("Shader Name").Append(',') .Append("Shader Types").Append(',') .Append("Pass Types").Append(',') .Append("Variant Count").Append(',') .Append("Keywords").Append(',') .Append('\n'); int totalVariantCount = 0; HashSet <string> totalKeywords = new HashSet <string>(); foreach (KeyValuePair <string, ShaderInfo> kv in m_ShaderInfos) { ShaderInfo shaderInfo = kv.Value; totalVariantCount += shaderInfo.VariantCount; foreach (string keyword in shaderInfo.Keywords) { totalKeywords.Add(keyword); } stringBuilder.Append(kv.Key).Append(',') .Append(string.Join(";", shaderInfo.ShaderTypes)).Append(',') .Append(string.Join(";", shaderInfo.PassTypes)).Append(',') .Append(shaderInfo.VariantCount).Append(',') .Append(string.Join(";", shaderInfo.Keywords)).Append(',') .Append('\n'); } string reportString = stringBuilder.ToString(); stringBuilder.Clear() .Append("Total Variant Count").Append(',').Append(totalVariantCount).Append('\n') .Append("Total Keywords").Append(',').Append(string.Join(";", totalKeywords)).Append('\n') .Append('\n'); reportString = stringBuilder.ToString() + reportString; try { string path = m_ReportDirectory + "/Summary.csv"; File.WriteAllText(path, reportString); MDebug.Log("Shader" , "Save PreprocessShaderReport Summary to " + MDebug.FormatPathToHyperLink(path)); } catch (Exception e) { MDebug.LogError("Shader" , "Save PreprocessShaderReport Summary Exception:\n" + e.ToString()); } stringBuilder.Clear(); stringBuilder.Append("Shader Name").Append(',') .Append("Variant Count").Append(',') .Append("\n"); foreach (KeyValuePair <string, int> kv in m_BuiltinShaders) { stringBuilder.Append(kv.Key).Append(",") .Append(kv.Value).Append(",") .Append("\n"); } try { string path = m_ReportDirectory + "/Builtin.csv"; File.WriteAllText(path, stringBuilder.ToString()); MDebug.Log("Shader" , "Save PreprocessShaderReport Builtin to " + MDebug.FormatPathToHyperLink(path)); } catch (Exception e) { MDebug.LogError("Shader" , "Save PreprocessShaderReport Builtin Exception:\n" + e.ToString()); } }
// -- Network Message 에 따른 애니메이션 처리 ---------------------------------------------------------------------------// void NetworkAnimation() { if (m_curState == (int)HERO_STATE.IDLE) { CheckAndSetAnimation(ANI_IDLE, true); } else { if (BitControl.Get(m_curState, (int)HERO_STATE.JUMP)) { // 점프 ㄱㄱ // IDLE / MOVE 상태일 때만 점프 애니메이션 if (IsCurrentAnimation(ANI_IDLE))// || IsCurrentAnimation(ANI_MOVE)) { //레디 -> 점핑 ㄱㄱ m_skletonAnimation.state.SetAnimation(0, ANI_JUMP_READY, false); m_skletonAnimation.state.AddAnimation(0, ANI_JUMP_JUMPING, true, 0f); } } if (BitControl.Get(m_curState, (int)HERO_STATE.JUMP_FALL)) { //떨어지는 중 if (!BitControl.Get(m_curState, (int)HERO_STATE.MOVE)) { CheckAndSetAnimation(ANI_JUMP_FALL, false); } } if (BitControl.Get(m_curState, (int)HERO_STATE.MOVE)) { if (!IsCurrentAnimation(ANI_MOVE)) { m_skletonAnimation.state.SetAnimation(0, ANI_MOVE, true); // } } if (BitControl.Get(m_curState, (int)HERO_STATE.LADDER)) { m_skletonAnimation.enabled = false; this.GetComponent <MeshRenderer>().enabled = false; m_climb.gameObject.SetActive(true); ShowWeapon(false); if (BitControl.Get(m_curState, (int)HERO_STATE.MOVE)) { if (m_climb.state.GetCurrent(0) != null && !m_climb.state.GetCurrent(0).animation.name.Equals("animation")) { m_climb.state.SetAnimation(0, "animation", true); } else if (m_climb.state.GetCurrent(0) == null) { m_climb.state.SetAnimation(0, "animation", true); } MDebug.Log("LADDER move"); } MDebug.Log("LADDER"); } else { ShowWeapon(true); m_skletonAnimation.enabled = true; this.GetComponent <MeshRenderer>().enabled = true; m_climb.gameObject.SetActive(false); //if(m_climb.state != null && m_climb.state.GetCurrent(0) != null) // m_climb.state.ClearTrack(0); } if (BitControl.Get(m_curState, (int)HERO_STATE.ATTACK)) { m_skletonAnimation.state.SetAnimation(1, ANI_REPAIR, false); } } }
private bool ParseDefineLine() { #region Convert to Reverse Polish notation // 这里用sring会产生大量的GC,但是这个函数只在初始化Lua脚本的时候调用,不会在游戏中频繁调用 string lastString = string.Empty; bool lastStringIsDefine = false; for (int iChar = 0; iChar < m_DefineLine.Length; iChar++) { char iterChar = m_DefineLine[iChar]; switch (iterChar) { case '!': if (lastString == string.Empty) { PushOperator(ItemType.Not); } else { ThrowParseDefineError(); } break; case '(': if (lastString == string.Empty) { PushOperator(ItemType.LParentheses); } else { ThrowParseDefineError(); } break; case ')': ParseOperator(ref lastString, ref lastStringIsDefine, ItemType.RParentheses); break; case '&': ParseReduplicationOperator(ref lastString , ref lastStringIsDefine , ItemType.And , "&"); break; case '|': ParseReduplicationOperator(ref lastString , ref lastStringIsDefine , ItemType.Or , "|"); break; case ' ': if (lastString != string.Empty) { if (lastStringIsDefine) { ParseValue(ref lastString, ref lastStringIsDefine); } else { ThrowParseDefineError(); } } break; default: if (lastString != string.Empty) { if (lastStringIsDefine) { lastString += iterChar; } else { ThrowParseDefineError(); } } else { lastString += iterChar; lastStringIsDefine = true; } break; } } ParseValue(ref lastString, ref lastStringIsDefine); MDebug.Assert(lastString == string.Empty, "XLua", "lastString == string.Empty"); while (m_ItemOperatorCache.Count > 0) { m_ItemCache.Enqueue(m_ItemOperatorCache.Pop()); } #endregion #region Caculate while (m_ItemCache.Count > 0) { ItemType itemType = m_ItemCache.Dequeue(); if (itemType == ItemType.True || itemType == ItemType.False) { m_ItemOperatorCache.Push(itemType); } else if (itemType == ItemType.Not) { MDebug.Assert(m_ItemOperatorCache.Count > 0, "XLua", "m_ItemOperatorCache.Count > 0"); ItemType operatorValue = m_ItemOperatorCache.Pop(); if (operatorValue == ItemType.True) { m_ItemOperatorCache.Push(ItemType.False); } else if (operatorValue == ItemType.False) { m_ItemOperatorCache.Push(ItemType.True); } else { ThrowParseDefineError(); } } else if (itemType == ItemType.And || itemType == ItemType.Or) { MDebug.Assert(m_ItemOperatorCache.Count > 1, "XLua", "m_ItemOperatorCache.Count > 1"); ItemType operatorValue1 = m_ItemOperatorCache.Pop(); ItemType operatorValue2 = m_ItemOperatorCache.Pop(); if ((operatorValue1 == ItemType.True || operatorValue1 == ItemType.False) && (operatorValue2 == ItemType.True || operatorValue2 == ItemType.False)) { if (itemType == ItemType.And) { m_ItemOperatorCache.Push((operatorValue1 == ItemType.True) && (operatorValue2 == ItemType.True) ? ItemType.True : ItemType.False); } else if (itemType == ItemType.Or) { m_ItemOperatorCache.Push((operatorValue1 == ItemType.True) || (operatorValue2 == ItemType.True) ? ItemType.True : ItemType.False); } else { ThrowParseDefineError(); } } else { ThrowParseDefineError(); } } else { ThrowParseDefineError(); } } #endregion if (m_ItemOperatorCache.Count != 1) { ThrowParseDefineError(); } ItemType resultItem = m_ItemOperatorCache.Pop(); bool result = false; switch (resultItem) { case ItemType.True: result = true; break; case ItemType.False: result = false; break; default: ThrowParseDefineError(); break; } MDebug.Log("XLua", $"Parse define: {result} = {m_DefineLine}"); return(result); }