private bool LoadMapFromBuffer(byte[] buf, string mapFileNameWithoutExtension) { //Clear ingnored traps list _ingnoredTrapsIndex.Clear(); FreeInternal(); //Clear asf cache, because normaly npcs objs will be cleared after map load. Utils.ClearTextureCache(); //Destory magic sprite in current map MagicManager.Renew(); var offset = 0; try { if (!LoadHead(buf, ref offset, mapFileNameWithoutExtension)) { return(false); } LoadMpc(buf, ref offset); LoadMapTiles(buf, ref offset); } catch (Exception e) { Log.LogMessage("Map file is corrupted" + ": " + e); } return(true); }
/// <summary> /// Load game from "save/game" directory /// GuiManager must started first /// </summary> public static void LoadGame(bool isInitlizeGame) { if (isInitlizeGame) { //Clear ScriptManager.Clear(); ScriptExecuter.Init(); MagicManager.Clear(); NpcManager.ClearAllNpc(); ObjManager.ClearAllObjAndFileName(); Globals.TheMap.Free(); GuiManager.CloseTimeLimit(); GuiManager.EndDialog(); BackgroundMusic.Stop(); Globals.IsInputDisabled = false; } LoadGameFile(); LoadMagicGoodMemoList(); LoadPlayer(); //Apply xiulian magic to player Globals.ThePlayer.XiuLianMagic = MagicListManager.GetItemInfo( MagicListManager.XiuLianIndex); LoadPartner(); LoadTraps(); LoadTrapIgnoreList(); Globals.TheCarmera.CenterPlayerInCamera(); GameState.State = GameState.StateType.Playing; Globals.TheGame.IsGamePlayPaused = false; GuiManager.ShowAllPanels(false); }
void Start() { selective.SetActive(false); magicManager = GameObject.Find("Player").GetComponent <MagicManager>(); spellSO = magic.GetComponent <Spell>().scriptableObject; gameObject.GetComponentInChildren <Text>().text = spellSO.name; }
public void InitializeMagicList(MagicId[] _availableMagic) { m_ListContainer.SetActive(true); m_SelectedMagic.gameObject.SetActive(false); m_SelectedMagic.onCancel.RemoveAllListeners(); m_SelectedMagic.onCancel.AddListener(() => { ShowMagicList(); }); int btnId = 0; foreach (MagicId id in _availableMagic) { if (btnId == m_BtnMagic.Length) { break; } MagicDescription desc = MagicManager.GetInstance().GetDescription(id); if (desc == null) { Debug.LogError(string.Format("Can't find magic description with id {0}", id)); continue; } CustomButton btn = m_BtnMagic[btnId]; btn.GetComponentInChildren <Text>().text = desc.m_DisplayName; btn.onCancel.RemoveAllListeners(); btn.onCancel.AddListener(() => { Close(); }); MagicId capturedId = id; //necessary for the lambda to work btn.onClick.RemoveAllListeners(); btn.onClick.AddListener(() => { Clicked(capturedId); }); btn.gameObject.SetActive(true); PawnStatistics stats = GameTurnManager.GetInstance().GetCurrentPawnStatistics(); if (desc.m_Power.CanBeUsed(stats)) { btn.IsUnselectable = false; } else { btn.IsUnselectable = true; } btn.Send(WidgetEvent.Unselect); ++btnId; } for (int i = btnId; i < m_BtnMagic.Length; ++i) { m_BtnMagic[i].gameObject.SetActive(false); } m_BtnMagic[0].Send(WidgetEvent.Select); }
void SweetStrike(Vector2 dirNormalized) { if (cooldownTimer > 0 || !MagicManager.attackTimerCleared) { return; } MagicManager.SetStaticAttackTimer(windupTime); cooldownTimer = strikeCooldown; StartCoroutine(SweetStrikeCoroutine(dirNormalized)); SweetMagicStrikeEvent?.Invoke(1, PlayerInputScript.instance.facing, windupTime + followThroughTime + 0.2f); }
void Spray(Vector2 dirNormalized) { if (attackCooldownTimer > 0 || !MagicManager.attackTimerCleared) { return; } MagicManager.SetStaticAttackTimer(windupTime + followThroughTime); attackCooldownTimer = attackCooldown; transform.rotation = Quaternion.Euler(0, 0, dirNormalized.Angle()); StartCoroutine(SprayCoroutine()); SavorySprayEvent?.Invoke(2, (int)Mathf.Sign(dirNormalized.x), followThroughTime + windupTime); }
void Clicked(MagicId _clickedMagicId) { m_ListContainer.SetActive(false); m_SelectedMagic.gameObject.SetActive(true); m_SelectedMagic.GetComponentInChildren <Text>().text = MagicManager.GetInstance().GetDescription(_clickedMagicId).m_DisplayName; m_SelectedMagic.SetFocus(); if (m_OnClicked != null) { m_OnClicked(_clickedMagicId); } }
void Start() { playerMovement = gameObject.GetComponent <PlayerMovementManager>(); magicManager = gameObject.GetComponent <MagicManager>(); uiManager = gameObject.GetComponent <UIManager>(); cameraManager = Camera.main.GetComponent <CameraManager>(); cameraPivot = gameObject.GetComponentInChildren <CameraPositionPivotManager>(); playerStatus = gameObject.GetComponent <PlayerStatus>(); lockOn = gameObject.GetComponent <LockOnManager>(); RightTrigger = AxisState.NotHeld; RightDPad = AxisState.NotHeld; LeftDPad = AxisState.NotHeld; UpDPad = AxisState.NotHeld; DownDPad = AxisState.NotHeld; HideCursor(); }
void Start() { var UIExposer = GameObject.FindGameObjectWithTag(Helpers.Tags.PlayerHUD).GetComponent <UIExposer>(); //playerPortrait = UIExposer.PlayerPortrait.GetComponent<Image>(); heartBackgroundsPanel = UIExposer.PlayerHeartBackgroundsPanel; heartsPanel = UIExposer.PlayerHeartsPanel; focusBar = UIExposer.PlayerFocusBar; readySpell = UIExposer.PlayerReadySpell.GetComponent <Image>(); magicManager = this.GetComponent <MagicManager>(); playerStatus = this.GetComponent <PlayerStatus>(); crosshair = Instantiate <GameObject>(crosshairObject).transform; gemsText = UIExposer.PlayerGemsCounter.GetComponent <Text>(); ToggleCrosshair(false); }
public override void OnInspectorGUI() { DrawDefaultInspector(); MagicManager mm = (MagicManager)target; //var v1 = mm.scale; //var v2 = mm.controller.rotation; //var v3 = Quaternion.SlerpUnclamped(Quaternion.identity, v2, v1); //// a * from = to //// a = to * ~from //// a //var v11 = mm.t1.rotation; //// b //var v22 = mm.t2.rotation; //// c //var v33 = v11 * v22; //var v111 = v33 * Quaternion.Inverse(v22); //mm.t3.rotation = v33; //var v11i = Quaternion.Inverse(v11); //var v4 = v11 * v11i; //EditorGUILayout.HelpBox(string.Format("org:{1:F3} | scale:{0} | target:{2:F3}", v1, v2, v3), MessageType.Info); //EditorGUILayout.HelpBox(string.Format("1:{0:F3} | 2:{1} | 3:{2:F3}", v11, v22, v33), MessageType.Info); //EditorGUILayout.HelpBox(string.Format("{0} {1} {2}", v11, v11i, v4), MessageType.Info); //EditorGUILayout.HelpBox(string.Format("{0} * {1} = {2}", v11, v22, v33), MessageType.Info); //EditorGUILayout.HelpBox(string.Format("{0} = {1} * ~ {2}", v111, v33, v22), MessageType.Info); }
private void OnMagicMagicSelected(MagicId _id) { //get the action MagicDescription desc = MagicManager.GetInstance().GetDescription(_id); ActionRunner magicAction = GameTurnManager.GetInstance().GetCurrentPawn().GetComponent <PawnActions>().GetAction(_id); magicAction.ActionDescription = desc; //set the action in the game master GameMaster.GetInstance().SetSelectedAction(magicAction); //show enemy selection WidgetManager.GetInstance().Show(m_CanvasEnemyList.gameObject, false, false); m_CanvasEnemyList.OnEnemySelected = OnMagicEnemySelected; m_CanvasEnemyList.OnCanvasClosed = OnMagicEnemyClosed; m_CanvasEnemyList.Show(); m_CanvasEnemyList.SetColumn(1); }
public override void LoadContent() { _charTex = UniversalVariables.content.Load <Texture2D>("SpriteSheet Char"); _char = new Character("Char", new Vector2(0, 0), _charTex, Color.White, SpriteEffects.None, 0, new Vector2(19, 29), .5f, "Standing", 0, true, AddCharAnims(), true, new List <GameAttribute>(), new List <Perk>(), new CharacterInventory(), 5f); base.LoadContent(); cam = new GameCam(_char, new Rectangle(250, 0, UniversalVariables.graphics.PreferredBackBufferWidth, UniversalVariables.graphics.PreferredBackBufferHeight)); _char.CurrentAnimation = "Standing"; mp = new Map(UniversalVariables.spriteBatch); Tiles = UniversalVariables.content.Load <Texture2D>("SpriteSheet Tiles"); GenerateMap(); Mous = new CompMouse("mouse", UniversalVariables.content.Load <Texture2D>("SpriteSheet Misc"), CreateMouseAnimation()); Mous.CurrentAnimation = "neutral"; MagMan = new MagicManager(UniversalVariables.content.Load <Texture2D>("SpriteSheet Magic"), new Rectangle(0, 14, 6, 6), new Rectangle(0, 0, 12, 12), new Rectangle(0, 12, 2, 2)); GenerateBaseEntityList(); Interface.Add(0, Mous); MagMan.AddPrimalShapes(); }
void Start() { //给测试英雄加上所有魔法 MagicManager.AddAllMagic(heroes[0]); //AdvantureObjectMgr.CreateAdvantureObject("Chest", new Vector2Int(23, 19)); //AdvantureObjectMgr.CreateAdvantureObject("Leorics", new Vector2Int(19, 17)); //AdvantureObjectMgr.CreateAdvantureObject("Chest", new Vector2Int(23, 14)); //AdvantureObjectMgr.CreateAdvantureObject("Gold", new Vector2Int(19, 14)); //AdvantureObjectMgr.CreateAdvantureObject("Gold", new Vector2Int(17, 14)); //AdvantureObjectMgr.CreateAdvantureObject("Gold", new Vector2Int(15, 14)); SkillManager.AddSkill(heroes[0], "Magic_Air", 2); SkillManager.AddSkill(heroes[0], "Magic_Fire", 2); SkillManager.AddSkill(heroes[0], "Magic_Earth", 2); SkillManager.AddSkill(heroes[0], "Magic_Water", 2); StartCoroutine(DelayStart()); }
// Use this for initialization void Start() { DontDestroyOnLoad(gameObject); if (instance == null) { instance = this; } Data.MagicProfileList = MagicProfileList; //NKTextMan.saveText("/MagicProfiles_.json", JsonUtility.ToJson(Data, true)); string json = SaveManager.LoadFixedJson("_Data/MagicProfiles"); JsonUtility.FromJsonOverwrite(json, Data); MagicProfileList = Data.MagicProfileList; foreach (MagicProfile i in MagicProfileList) { i.ParseStr(); } this.gameObject.SetActive(false); }
private void Awake() { instance = this; }
/// <summary> /// Causes the user to attack its current target with the current Item as the weapon. If the user's target is a mobile /// a counter attack check will occur and if successful the mobile will counter attack. /// </summary> /// <param name="weapon">The current item to use as a weapon.</param> /// <param name="user">The actor instance using the item as a weapon.</param> public static void Attack(this Item weapon, IActor user) { //if (user is IAvatar) //{ // if ((user as IAvatar).CombatMatch != Guid.Empty) // { // // Already engaged in combat, ignore the command. // } // else // { // // If the target is already engaged then join the match?? // } //} try { IAvatar avatar, target; IAvatar defender = null; IAvatar attacker = null; avatar = user as IAvatar; if (avatar != null) { if (avatar.Target != null && avatar.Target is IAvatar) { target = avatar.Target as IAvatar; // If the target is the user then exit. if (avatar.ID == target.ID) { avatar.Context.Add(new RdlErrorMessage(Resources.CanNotAttackSelf)); return; } // Target must also have the avatar targeted or be set to null. if (target.Target == null) { target.Target = avatar; } else if (target.Target.ID != avatar.ID) { avatar.Context.Add(new RdlErrorMessage(String.Format(Resources.TargetEngaged, target.TheUpper()))); return; } // Check for death and unconsioussness. if (avatar.IsDead) { avatar.Context.Add(new RdlErrorMessage(Resources.PlayerDead)); return; } if (avatar.IsUnconscious) { avatar.Context.Add(new RdlErrorMessage(Resources.PlayerUnconscious)); return; } if (target.IsDead) { avatar.Context.Add(new RdlErrorMessage(Resources.TargetDead)); return; } // Can not attack certain mobiles, need to check for safe mobiles. if (target is PerenthiaMobile && !(target as PerenthiaMobile).CanAttack) { avatar.Context.Add(new RdlErrorMessage(String.Format(Resources.ActionCanNotPerform, target.A()))); return; } // Can not attack a Character unless the IsPvpEnabled is set to true. if (target is Character) { if (avatar is Character && !(target as Character).IsPvpEnabled) { avatar.Context.Add(new RdlErrorMessage(String.Format(Resources.ActionCanNotPerform, target.A()))); return; } } // Increase the skill of the player using the item. IPlayer currentPlayer = null; string skill = null; if (avatar is IPlayer) { currentPlayer = avatar as IPlayer; skill = weapon.GetOffensiveSkill(); } else if (target is IPlayer) { currentPlayer = target as IPlayer; skill = target.GetDefensiveSkill(); } if (weapon is Spell) { skill = weapon.Skill; } if (currentPlayer != null && !(weapon is Spell)) { // NOTE: Skill advancement occuring in combat and magic manager classes. // Advance the skill of the current player. //SkillManager.AdvanceSkill(currentPlayer, skill, weapon.SkillLevelRequiredToEquip, currentPlayer.Context); } bool performCounterAttack = false; if (weapon is Spell) { // CAST A SPELL CastResults results = MagicManager.PerformCast((ISpell)weapon, avatar, target); if (results.TargetDied) { attacker = avatar; defender = target; } else { // If the target is a mobile then counter attack. if (!avatar.IsDead && target is IMobile && !target.IsDead && !target.IsUnconscious) { performCounterAttack = true; } } } else { // USE A WEAPON if (CombatManager.PerformSimpleCombatTurn( avatar, (IWeapon)weapon, target, target.GetDefensiveSkill(), AttributeType.Dexterity, 0)) { // Killed defender. attacker = avatar; defender = target; } else { // DUAL WIELD // If attacker has dual wield skill and an equipped second weapon then // perform another attack. IWeapon secondaryWeapon = avatar.GetSecondaryWeapon(); if (secondaryWeapon != null) { if (CombatManager.PerformSimpleCombatTurn( avatar, secondaryWeapon, "Dual Wield", target, target.GetDefensiveSkill(), AttributeType.Dexterity, 0)) { // Killed defender. attacker = avatar; defender = target; } else { // Defender counter attack. // Only counter if a mobile. if (target is IMobile && !target.IsDead && !target.IsUnconscious) { performCounterAttack = true; } } } else { // Defender counter attack. // Only counter if a mobile. if (target is IMobile && !target.IsDead && !target.IsUnconscious) { performCounterAttack = true; } } } } if (performCounterAttack) { if (!target.IsStunned && !target.IsFrozen && !avatar.IsDead) { // TODO: Have mobiles attack with spells?? // USE A WEAPON if (CombatManager.PerformSimpleCombatTurn( target, target.GetWeapon(), avatar, avatar.GetDefensiveSkill(), AttributeType.Dexterity, 0)) { // Killed attacker. attacker = target; defender = avatar; } // Update the mobile's last attack time. (target as PerenthiaMobile).LastAttackTime = DateTime.Now; } } // Send down stats for both attacker and defender. var attackerProps = avatar.GetRdlProperties(Avatar.BodyProperty, Avatar.MindProperty); var defenderProps = target.GetRdlProperties(Avatar.BodyProperty, Avatar.MindProperty); avatar.Context.AddRange(attackerProps); avatar.Context.AddRange(defenderProps); target.Context.AddRange(attackerProps); target.Context.AddRange(defenderProps); if (defender != null && attacker != null) { if (attacker is IPlayer) { //========================================================================================= // PLAYER KILLED MOBILE //========================================================================================= // The mobile dies, cause it to respawn at a later date. PerenthiaMobile mob = defender as PerenthiaMobile; if (mob != null) { // Mobile is a clone but is stored as an instance on the mobile object. DateTime killTime = DateTime.Now; mob.RespawnTime = killTime.Add(mob.RespawnDelay); mob.KilledBy.AddKilledBy(attacker.ID, killTime); } attacker.Context.AddRange(defender.ToSimpleRdl()); // Since the player killed the mobile, give them some experience. Character player = attacker as Character; if (player != null && mob != null) { int xp = LevelManager.GetXpForMobileKill(player.Level, mob.Level); if (xp > 0) { player.Experience += xp; player.TotalExperience += xp; player.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Positive, String.Format(Resources.ExperienceGained, xp))); } // Raise an event indicating that the player has killed something. player.World.OnAvatarKilledAvatar(player, mob); // Raise an internal event on the player instance for quests and awards. player.OnKilledActor(mob); // Cause the player to advance if the required experience requirements are met. LevelManager.AdvanceIfAble(player); // Mobiles should drop random items, mostly items related to crafting. mob.GenerateRandomDropItems(); // Send down changed properties. player.Context.AddRange(player.GetRdlProperties( Character.ExperienceProperty, Character.ExperienceMaxProperty, Character.CurrencyProperty)); // Save the player instance. player.Save(); } } else if (defender is IPlayer) { //========================================================================================= // MOBILE KILLED PLAYER //========================================================================================= // A player died, dock some experience. // Only loose experience after level 5. Character player = defender as Character; if (player != null && player.Experience > 0 && player.Level > 5) { int penaltyXp = player.Level * 50 + (Dice.Roll(player.Level, 10)); if (penaltyXp > player.Experience) { penaltyXp = player.Experience - 2; } player.Experience -= penaltyXp; player.TotalExperience -= penaltyXp; player.Context.Add(new RdlSystemMessage(RdlSystemMessage.PriorityType.Negative, String.Format(Resources.ExperienceLost, penaltyXp))); // Send down changed properties. player.Context.AddRange(player.GetRdlProperties( Character.ExperienceProperty, Character.ExperienceMaxProperty)); } // Raise an event on the player for quests and awards. if (defender != null) { player.OnDied(defender); } if (attacker != null && defender != null) { // Raise an event indicating that the defender has killed the attacker. defender.World.OnAvatarKilledAvatar(attacker, defender); } // Find the nearest temple and resurrect the player there. Temple temple = Game.FindTemple(defender.Location); if (temple != null) { temple.Resurrect(defender); } else { // Otherwise, spaw a temple right above the player's starting location and send them there. Race race = defender.World.Races[defender.Race]; Temple newTemple = new Temple() { Location = new Point3(race.StartingLocation.X, race.StartingLocation.Y, race.StartingLocation.Z + 1), Name = "Temple", World = defender.World, Terrain = defender.World.Terrain[1].ID, }; newTemple.Exits.SetValue(KnownDirection.Down, true); defender.World.Places.Add(newTemple.Location, newTemple); Game.AddTemple(newTemple); } // Save the player instance. defender.Save(); } // Do not reset targets after combat as the target might be clone of a mob and will need // to remain set for proper looting. // Reset targets. //attacker.Target = null; //defender.Target = null; //attacker.Context.AddRange(attacker.GetRdlProperties(Avatar.TargetIDProperty)); //defender.Context.AddRange(defender.GetRdlProperties(Avatar.TargetIDProperty)); } } else { avatar.Context.Add(new RdlErrorMessage(String.Format("You must have a target selected to use {0}.", weapon.The()))); } } } catch (Exception ex) { throw ex; } }
private void PerformRound() { _isPerformingRound = true; // Combine contestants into one array. var contestants = new IAvatar[_attackers.Length + _defenders.Length]; Array.Copy(_attackers, 0, contestants, 0, _attackers.Length); Array.Copy(_defenders, 0, contestants, _attackers.Length, _defenders.Length); // Roll for initiative. CombatManager.DetermineInitiative(InitiativeType.Individual, contestants); // Sort the contestants based on initiative. Array.Sort <IAvatar>(contestants, new Comparison <IAvatar>((m1, m2) => { return((m1.Initiative).CompareTo(m2.Initiative)); })); // Perform the specified action for each contestant based on initiative. // NOTE: Contestants should have chosen targets during the combat action selection. for (int i = 0; i < contestants.Length; i++) { if (contestants[i].CanPerformAction) { // Find the object defined in the combat action. var item = contestants[i].World.GetActor(contestants[i].CombatAction, contestants[i]) as IItem; if (item == null) { continue; } // Ensure contestant has a target set. if (contestants[i].Target == null || !(contestants[i].Target is IAvatar)) { continue; } if (item is IWeapon) { var defender = contestants[i].Target as IAvatar; // Perform simple combat turn. CombatManager.PerformSimpleCombatTurn( contestants[i], item as IWeapon, defender, defender.GetDefensiveSkill(), AttributeType.Dexterity, 0); } else if (item is ISpell) { MagicManager.PerformCast(item as ISpell, contestants[i], contestants[i].Target); } else { // Use the item. item.Use(contestants[i], contestants[i].Context); } } } // Clear the combat action for each contestant. ClearActionResponse(contestants); // Determine if the match is complete. _isMatchComplete = IsMatchComplete(); if (_isMatchComplete) { OnComplete(); } _isPerformingRound = false; }
private void Awake() { m_template = new GesturesTemplate(); scr_magicManager = GetComponent <MagicManager>(); }
public PlayerInfo() { this.sittingInfo = new SittingInfo(); this.magicManager = new MagicManager(); }