public void UpdateMap(string newMap) { //Load Config string[] lines = newMap.Split('\n'); int c = 0; for (c = 0; c < lines.Length; c++) { string lines_nr = lines [c].Split('\r') [0]; string[] splits = lines_nr.Split('='); if (splits.Length >= 2) { if (splits [0].ToLower() == "offsetx") { int term = 0; if (int.TryParse(splits [1], out term)) { Offset.x = term; } } if (splits [0].ToLower() == "offsety") { int term = 0; if (int.TryParse(splits [1], out term)) { Offset.y = term; } } if (splits [0].ToLower() == "cellx") { float term = 0; if (float.TryParse(splits [1], out term)) { CellSize.x = term; } } if (splits [0].ToLower() == "celly") { float term = 0; if (float.TryParse(splits [1], out term)) { CellSize.y = term; } } if (splits [0].ToLower() == "singledisp") { int term = 0; if (int.TryParse(splits [1], out term)) { SingleMode = term == 1; } } } if (lines_nr == "#Map") { break; } } c++; Debug.Log(string.Format("Offset is {0}", Offset)); Debug.Log(string.Format("SingleDipslay is {0}", SingleMode)); //Load mapData int maxLengthX = 0; int maxLengthY = 0; for (int y = c; y < lines.Length; y++) { string lines_nr = lines [y].Split('\r') [0]; if (lines_nr == "#End") { break; } maxLengthY++; string[] raw_datas; if (SingleMode) { char[] raw_datas_charArr = lines_nr.ToCharArray(); raw_datas = new string[raw_datas_charArr.Length]; for (int i = 0; i < raw_datas_charArr.Length; i++) { raw_datas [i] = new string (new char[] { raw_datas_charArr [i] }); } } else { raw_datas = lines_nr.Split(','); } for (int x = 0; x < raw_datas.Length; x++) { mapData [x, y - c] = raw_datas [x]; } maxLengthX = maxLengthX < raw_datas.Length ? raw_datas.Length : maxLengthX; } //Turn Pattern By Center and Justify array length; string[,] turnedData = new string[maxLengthX, maxLengthY]; int lenX = maxLengthX; int lenY = maxLengthY; switch (MapCenter) { case CenterType.TopLeft: for (int y = 0; y < lenY; y++) { for (int x = 0; x < lenX; x++) { turnedData [x, y] = mapData [x, y]; } } break; case CenterType.TopRight: for (int y = 0; y < lenY; y++) { for (int x = 0; x < lenX; x++) { turnedData [x, y] = mapData [lenX - x - 1, y]; } } break; case CenterType.BottomLeft: for (int y = 0; y < lenY; y++) { for (int x = 0; x < lenX; x++) { turnedData [x, y] = mapData [x, lenY - y - 1]; } } break; case CenterType.BottomRight: for (int y = 0; y < lenY; y++) { for (int x = 0; x < lenX; x++) { turnedData [x, y] = mapData [lenX - x - 1, lenY - y - 1]; } } break; } mapData = (string[, ])turnedData.Clone(); //put sprites Vector3 lastPosition = this.transform.position; this.transform.position = Vector3.zero; for (int y = 0; y < mapData.GetLength(1); y++) { if (y == 0) { if (MapCenter == CenterType.BottomLeft || MapCenter == CenterType.BottomRight) { CurrentPosition += new Vector2(0, CellSize.y); } } for (int x = 0; x < mapData.GetLength(0); x++) { string key = mapData [x, y]; int num = GetKeyNum(key); Vector2 putPosition = new Vector2( Offset.x * CellSize.x + (MapCenter == CenterType.TopLeft ? CellSize.x / 2 : MapCenter == CenterType.TopRight ? -CellSize.x / 2 : MapCenter == CenterType.BottomLeft ? CellSize.x / 2 : -CellSize.x / 2), Offset.y * CellSize.y + (MapCenter == CenterType.TopLeft ? CellSize.y / 2 : MapCenter == CenterType.TopRight ? CellSize.y / 2 : MapCenter == CenterType.BottomLeft ? -CellSize.y / 2 : -CellSize.y / 2)); if (num < 0) { CurrentPosition += new Vector2((MapCenter == CenterType.TopLeft || MapCenter == CenterType.BottomLeft ? 1 : -1) * CellSize.x, 0); continue; } GameObject childObj = new GameObject(); GeneralTrigger generalTrigger = childObj.GetComponent <GeneralTrigger> (); //特殊 switch (SpriteColliderTypes [num]) { case ColliderType.Start: childObj = new GameObject("StartPoint"); childObj.transform.position = new Vector3( ((CurrentPosition + putPosition) * Scale.x).x + (lastPosition).x, ((CurrentPosition + putPosition) * Scale.y).y + (lastPosition).y, 0); PlayerObject.transform.position = childObj.transform.position; StartPoint = childObj.transform.position; RespornPoint = childObj.transform.position; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; goto case ColliderType.Default; case ColliderType.End: childObj = new GameObject("GoalPoint", typeof(Rigidbody2D), typeof(PolygonCollider2D), typeof(GeneralTrigger)); Rigidbody2D endTriggerRigid = childObj.GetComponent <Rigidbody2D> (); endTriggerRigid.isKinematic = true; PolygonCollider2D endTrigger = childObj.GetComponent <PolygonCollider2D> (); endTrigger.pathCount = 1; endTrigger.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); endTrigger.isTrigger = true; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; generalTrigger = childObj.GetComponent <GeneralTrigger> (); generalTrigger.thisTriggerType = GeneralTrigger.TriggerType.Goal; goto case ColliderType.Default; case ColliderType.GameOverZone: childObj = new GameObject("OutZone", typeof(Rigidbody2D), typeof(PolygonCollider2D), typeof(GeneralTrigger)); Rigidbody2D OutZoneRigid = childObj.GetComponent <Rigidbody2D> (); OutZoneRigid.isKinematic = true; PolygonCollider2D outTrigger = childObj.GetComponent <PolygonCollider2D> (); outTrigger.pathCount = 1; outTrigger.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); outTrigger.isTrigger = true; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; childObj.transform.tag = "DamageObject"; generalTrigger = childObj.GetComponent <GeneralTrigger> (); generalTrigger.thisTriggerType = GeneralTrigger.TriggerType.Out; goto case ColliderType.Default; case ColliderType.CheckPoint: childObj = new GameObject("CheckPoint", typeof(Rigidbody2D), typeof(PolygonCollider2D), typeof(GeneralTrigger)); Rigidbody2D CheckPointRigid = childObj.GetComponent <Rigidbody2D> (); CheckPointRigid.isKinematic = true; PolygonCollider2D CheckPointTrigger = childObj.GetComponent <PolygonCollider2D> (); CheckPointTrigger.pathCount = 1; CheckPointTrigger.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); CheckPointTrigger.isTrigger = true; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; generalTrigger = childObj.GetComponent <GeneralTrigger> (); generalTrigger.thisTriggerType = GeneralTrigger.TriggerType.CheckPoint; generalTrigger.CheckPointNum = GeneralTrigger.CheckPointMax++; childObj.name = "CheckPoint_" + generalTrigger.CheckPointNum; goto case ColliderType.Default; case ColliderType.LeftSpeeder: childObj = new GameObject("LeftSpeeder", typeof(Rigidbody2D), typeof(PolygonCollider2D), typeof(GeneralTrigger)); Rigidbody2D LeftSpeederRigid = childObj.GetComponent <Rigidbody2D> (); LeftSpeederRigid.isKinematic = true; PolygonCollider2D LeftSpeederTrigger = childObj.GetComponent <PolygonCollider2D> (); LeftSpeederTrigger.pathCount = 1; LeftSpeederTrigger.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); LeftSpeederTrigger.isTrigger = true; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; generalTrigger = childObj.GetComponent <GeneralTrigger> (); generalTrigger.thisTriggerType = GeneralTrigger.TriggerType.SpeedUp_L; goto case ColliderType.Default; case ColliderType.RightSpeeder: childObj = new GameObject("RightSpeeder", typeof(Rigidbody2D), typeof(PolygonCollider2D), typeof(GeneralTrigger)); Rigidbody2D RightSpeederRigid = childObj.GetComponent <Rigidbody2D> (); RightSpeederRigid.isKinematic = true; PolygonCollider2D RightSpeederTrigger = childObj.GetComponent <PolygonCollider2D> (); RightSpeederTrigger.pathCount = 1; RightSpeederTrigger.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); RightSpeederTrigger.isTrigger = true; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; generalTrigger = childObj.GetComponent <GeneralTrigger> (); generalTrigger.thisTriggerType = GeneralTrigger.TriggerType.SpeedUp_R; goto case ColliderType.Default; case ColliderType.Jumper: childObj = new GameObject("Jumper", typeof(Rigidbody2D), typeof(PolygonCollider2D), typeof(GeneralTrigger)); Rigidbody2D JumperRigid = childObj.GetComponent <Rigidbody2D> (); JumperRigid.isKinematic = true; PolygonCollider2D JumperTrigger = childObj.GetComponent <PolygonCollider2D> (); JumperTrigger.pathCount = 1; JumperTrigger.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); JumperTrigger.isTrigger = true; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; generalTrigger = childObj.GetComponent <GeneralTrigger> (); generalTrigger.thisTriggerType = GeneralTrigger.TriggerType.SpeedUp_U; goto case ColliderType.Default; case ColliderType.Stomper: childObj = new GameObject("Jumper", typeof(Rigidbody2D), typeof(PolygonCollider2D), typeof(GeneralTrigger)); Rigidbody2D StomperRigid = childObj.GetComponent <Rigidbody2D> (); StomperRigid.isKinematic = true; PolygonCollider2D StomperTrigger = childObj.GetComponent <PolygonCollider2D> (); StomperTrigger.pathCount = 1; StomperTrigger.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); StomperTrigger.isTrigger = true; childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; generalTrigger = childObj.GetComponent <GeneralTrigger> (); generalTrigger.thisTriggerType = GeneralTrigger.TriggerType.SpeedUp_D; goto case ColliderType.Default; case ColliderType.None: childObj = new GameObject("Null_Object"); childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; goto case ColliderType.Default; case ColliderType.Default: if (generalTrigger != null) { generalTrigger.UC2DC = this.UC2DC; } if (GetSprite(num) != null) { Sprite backSpr = Instantiate <Sprite> (GetSprite(num)); SpriteRenderer backRnd = childObj.AddComponent <SpriteRenderer> (); backRnd.sprite = backSpr; backRnd.color = Color.white; } CurrentPosition += new Vector2((MapCenter == CenterType.TopLeft || MapCenter == CenterType.BottomLeft ? 1 : -1) * CellSize.x, 0); continue; } if (GetSprite(num) == null) { CurrentPosition += new Vector2((MapCenter == CenterType.TopLeft || MapCenter == CenterType.BottomLeft ? 1 : -1) * CellSize.x, 0); continue; } Sprite child = Instantiate <Sprite> (GetSprite(num)); childObj = new GameObject(string.Format("map_x{0:D4}_y{1:D4}", x, y), typeof(SpriteRenderer), typeof(PolygonCollider2D)); SpriteRenderer childRnd = childObj.GetComponent <SpriteRenderer> (); childRnd.sprite = child; childRnd.color = Color.white; PolygonCollider2D childCol = childObj.GetComponent <PolygonCollider2D> (); childCol.pathCount = 1; switch (SpriteColliderTypes [num]) { case ColliderType.Box: childCol.enabled = false; int rx = GetBlockLengthX(x, y); int ry = GetBlockLengthY(x, y); if (rx > 0) { if (!isAlreadyColl(x, y, 0)) { childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x * (rx - 1) + CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x * (rx - 1) + CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y / 2) }); childCol.enabled = true; //Y方向も if (ry > 0) { if (!isAlreadyColl(x, y, 1)) { childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, CellSize.y * (ry - 1) + CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y * (ry - 1) + CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(CellSize.x * (rx - 1) + CellSize.x / 2, CellSize.y / 2), new Vector2(CellSize.x * (rx - 1) + CellSize.x / 2, -CellSize.y / 2), new Vector2(-CellSize.x / 2, -CellSize.y / 2) }); childCol.enabled = true; } } } else { if (ry > 0) { if (!isAlreadyColl(x, y, 1)) { childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y * (ry - 1) + CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y * (ry - 1) + CellSize.y / 2) }); childCol.enabled = true; } } } } else if (ry > 0) { if (!isAlreadyColl(x, y, 1)) { childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y * (ry - 1) + CellSize.y / 2), new Vector2(-CellSize.x / 2, CellSize.y * (ry - 1) + CellSize.y / 2) }); childCol.enabled = true; } } break; case ColliderType.UpTriangle: childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, -CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2) }); break; case ColliderType.DownTriangle: childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2), new Vector2(-CellSize.x / 2, -CellSize.y / 2) }); break; case ColliderType.UpRevTriangle: childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(-CellSize.x / 2, -CellSize.y / 2) }); break; case ColliderType.DownRevTriangle: childCol.SetPath(0, new Vector2[] { new Vector2(-CellSize.x / 2, CellSize.y / 2), new Vector2(CellSize.x / 2, CellSize.y / 2), new Vector2(CellSize.x / 2, -CellSize.y / 2) }); break; } childObj.transform.position = this.transform.position; childObj.transform.position = CurrentPosition + putPosition; childObj.transform.parent = this.transform; childObj.layer = 8; CurrentPosition += new Vector2((MapCenter == CenterType.TopLeft || MapCenter == CenterType.BottomLeft ? 1 : -1) * CellSize.x, 0); } CurrentPosition.x = 0; CurrentPosition += new Vector2(0, (MapCenter == CenterType.TopLeft || MapCenter == CenterType.TopRight ? -1 : 1) * CellSize.y); } //Scaling this.transform.localScale = new Vector3(Scale.x, Scale.y, 1); //Back to position this.transform.position = lastPosition; //StartGame ActionEnd = false; }
public void Load(string id) { MongoUtils.MongoData.ConnectToDatabase(); MongoDatabase characterDB = MongoUtils.MongoData.GetDatabase("Characters"); MongoCollection characterCollection = characterDB.GetCollection <BsonDocument>("NPCCharacters"); IMongoQuery query = Query.EQ("_id", ObjectId.Parse(id)); BsonDocument found = characterCollection.FindOneAs <BsonDocument>(query); ID = found["_id"].AsObjectId.ToString(); FirstName = found["FirstName"].AsString.CamelCaseWord(); LastName = found["LastName"].AsString.CamelCaseWord(); _class = (CharacterClass)Enum.Parse(typeof(CharacterClass), found["Class"].AsString.CamelCaseWord()); _race = (CharacterRace)Enum.Parse(typeof(CharacterRace), found["Race"].AsString.CamelCaseWord()); _gender = (Genders)Enum.Parse(typeof(Genders), found["Gender"].AsString.CamelCaseWord()); _skinType = (SkinType)Enum.Parse(typeof(SkinType), found["SkinType"].AsString.CamelCaseWord()); _skinColor = (SkinColors)Enum.Parse(typeof(SkinColors), found["SkinColor"].AsString.CamelCaseWord()); _skinType = (SkinType)Enum.Parse(typeof(SkinType), found["SkinType"].AsString.CamelCaseWord()); _hairColor = (HairColors)Enum.Parse(typeof(HairColors), found["HairColor"].AsString.CamelCaseWord()); _eyeColor = (EyeColors)Enum.Parse(typeof(EyeColors), found["EyeColor"].AsString.CamelCaseWord()); _stanceState = (CharacterStanceState)Enum.Parse(typeof(CharacterStanceState), found["StanceState"].AsString.CamelCaseWord()); _actionState = (CharacterActionState)Enum.Parse(typeof(CharacterActionState), found["ActionState"].AsString.CamelCaseWord()); Description = found["Description"].AsString; Location = found["Location"].AsString; Height = found["Height"].AsDouble; Weight = found["Weight"].AsDouble; IsNPC = found["IsNPC"].AsBoolean; MobTypeID = found["MobTypeID"].AsInt32; NextAiAction = found["NextAiAction"].ToUniversalTime(); InCombat = found["InCombat"].AsBoolean; LastCombatTime = found["LastCombatTime"].ToUniversalTime(); CurrentTarget = found["CurrentTarget"].AsString != "" ? found["CurrentTarget"].AsString : null; LastTarget = found["LastTarget"].AsString != "" ? found["LastTarget"].AsString : null; Fsm.state = Fsm.GetStateFromName(found["AiState"].AsString); Fsm.previousState = Fsm.GetStateFromName(found["previousAiState"].AsString); Fsm.globalState = Fsm.GetStateFromName(found["AiGlobalState"].AsString); Experience = found["Experience"].AsInt64; Level = found["Level"].AsInt32; Title = found.Contains("Title") ? found["Title"].AsString : ""; KillerID = found.Contains("KillerID") ? found["KillerID"].AsString : ""; //if you just use var instead of casting it like this you will be in a world of pain and suffering when dealing with subdocuments. BsonArray playerAttributes = found["Attributes"].AsBsonArray; BsonArray xpTracker = found["XpTracker"].AsBsonArray; BsonDocument triggers = found["Triggers"].AsBsonDocument; BsonArray bonusesList = null; if (found.Contains("Bonuses")) { bonusesList = found["Bonuses"].AsBsonArray; } if (playerAttributes != null) { foreach (BsonDocument attrib in playerAttributes) { if (!this.Attributes.ContainsKey(attrib["Name"].ToString())) { Attribute tempAttrib = new Attribute(); tempAttrib.Name = attrib["Name"].ToString(); tempAttrib.Value = attrib["Value"].AsDouble; tempAttrib.Max = attrib["Max"].AsDouble; tempAttrib.RegenRate = attrib["RegenRate"].AsDouble; this.Attributes.Add(tempAttrib.Name, tempAttrib); } else { this.Attributes[attrib["Name"].ToString()].Max = attrib["Max"].AsDouble; this.Attributes[attrib["Name"].ToString()].Value = attrib["Value"].AsDouble; this.Attributes[attrib["Name"].ToString()].RegenRate = attrib["RegenRate"].AsDouble; } } } if (xpTracker != null && xpTracker.Count > 0) { foreach (BsonDocument track in xpTracker) { //we just newed this up so it should always have to be refilled damageTracker.Add(track["ID"].AsString, track["Value"].AsDouble); } } ITrigger trigger = new GeneralTrigger(triggers, "NPC"); Triggers.Add(trigger); if (bonusesList != null && bonusesList.Count > 0) { Bonuses.LoadFromBson(bonusesList); } }