925 lines
38 KiB
C#
925 lines
38 KiB
C#
/********************************************************************
|
||
日期: 2014/03/01
|
||
文件: Obj_MainPlayer_Auto.cs
|
||
路径: D:\work\code\mldj\Version\Main\Project\Client\Assets\MLDJ\Script\Obj\Obj_MainPlayer_Auto.cs
|
||
作者: YangXin
|
||
描述: 人物挂机
|
||
修改:
|
||
*********************************************************************/
|
||
using System;
|
||
using System.Collections;
|
||
using UnityEngine;
|
||
using Games.GlobeDefine;
|
||
using System.Collections.Generic;
|
||
using Games.Item;
|
||
using GCGame.Table;
|
||
using UnityEngine.Events;
|
||
|
||
namespace Games.LogicObj
|
||
{
|
||
public partial class Obj_MainPlayer
|
||
{
|
||
public const float autoCombatRecoverDelay = 10f;
|
||
|
||
public bool isAutoCombat
|
||
{
|
||
get { return _isAutoCombat; }
|
||
set
|
||
{
|
||
if (_isAutoCombat != value)
|
||
{
|
||
_isAutoCombat = value;
|
||
if (ChatFrameLogic.Instance() != null)
|
||
ChatFrameLogic.Instance().UpdateAutoFightBtnState();
|
||
}
|
||
}
|
||
}
|
||
|
||
private bool _isAutoCombat;
|
||
|
||
// 在这个时间后,恢复自动战斗
|
||
private float _autoCombatRecovery = -1f;
|
||
|
||
// 注:临时使用这个接口,作为打断任意自动行为的接口
|
||
public void BreakAutoCombatState()
|
||
{
|
||
if (isAutoCombat)
|
||
{
|
||
var willRecover = GameManager.gameManager.ActiveScene.IsCopyScene()
|
||
&& ChatFrameLogic.AllowAutoFight();
|
||
if (willRecover)
|
||
{
|
||
var sceneDefine = (GameDefine_Globe.SCENE_DEFINE) GameManager.gameManager.RunningScene;
|
||
willRecover = sceneDefine != GameDefine_Globe.SCENE_DEFINE.SCENE_GUILD
|
||
&& sceneDefine != GameDefine_Globe.SCENE_DEFINE.SCENE_GUAJI;
|
||
}
|
||
if (willRecover)
|
||
{
|
||
isAutoCombat = false;
|
||
_autoCombatRecovery = Time.unscaledTime + autoCombatRecoverDelay;
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{42103}"));
|
||
}
|
||
else
|
||
LeveAutoCombat();
|
||
}
|
||
else if (_autoCombatRecovery > 0f)
|
||
_autoCombatRecovery = Time.unscaledTime + autoCombatRecoverDelay;
|
||
}
|
||
|
||
public bool GetAutoCombatState()
|
||
{
|
||
if (Controller)
|
||
{
|
||
return Controller.CombatFlag;
|
||
}
|
||
return false;
|
||
}
|
||
/// <summary>
|
||
/// 延迟1秒进入自动战斗
|
||
/// </summary>
|
||
// 主要用于进入副本,自动切入的情况
|
||
// 只有进入地图开始一帧会调用,性能需求低
|
||
public void EnterAutoCombatAfterLoading()
|
||
{
|
||
if (LoadingWindow._IsLoadingScene)
|
||
StartCoroutine(AfterLoadingCoroutine(EnterAutoCombat));
|
||
else
|
||
EnterAutoCombat();
|
||
}
|
||
|
||
IEnumerator AfterLoadingCoroutine(UnityAction action)
|
||
{
|
||
while (LoadingWindow._IsLoadingScene)
|
||
yield return null;
|
||
action();
|
||
}
|
||
|
||
public void EnterAutoCombat()
|
||
{
|
||
if (Controller)
|
||
{
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{42101}"));
|
||
Controller.EnterCombat();
|
||
isAutoCombat = true;
|
||
_autoCombatRecovery = -1f;
|
||
UpdateSellItem(); //自动卖药
|
||
LockJoyStick();
|
||
GameManager.gameManager.AutoSearch.Stop();
|
||
BreakMeditate();
|
||
}
|
||
}
|
||
|
||
public void BreakMeditate()
|
||
{
|
||
if (MeditateProgress.Instance && MeditateProgress.Instance.isActiveAndEnabled)
|
||
UIManager.CloseUI(UIInfo.MeditateProgress);
|
||
|
||
if (Singleton<ObjManager>.Instance.MainPlayer
|
||
&& Singleton<ObjManager>.Instance.MainPlayer.CurObjAnimState == GameDefine_Globe.OBJ_ANIMSTATE.STATE_FINSH)
|
||
{
|
||
Singleton<ObjManager>.Instance.MainPlayer.OnSwithObjAnimState(GameDefine_Globe.OBJ_ANIMSTATE.STATE_NORMOR);
|
||
}
|
||
}
|
||
|
||
public void LeveAutoCombat()
|
||
{
|
||
_autoCombatRecovery = -1f;
|
||
if (isAutoCombat)
|
||
{
|
||
if (Controller)
|
||
{
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{42102}"));
|
||
Controller.LeaveCombat();
|
||
isAutoCombat = false;
|
||
// 取消自动战斗期间推送的移动和PendingSkill
|
||
if (!_isAutoCombat)
|
||
{
|
||
if (MovementState == MoveState.MainPlayMove)
|
||
StopMove();
|
||
CleanPendingSkill();
|
||
}
|
||
}
|
||
var autoAttack =
|
||
CommonUtility.IsAutoCombatCopyScene(GameManager.gameManager.PlayerDataPool.EnterSceneCache
|
||
.EnterCopySceneID);
|
||
// 非自动战斗副本中,队长解除自动战斗,会修改其他队员的状态
|
||
if (!autoAttack && GameManager.gameManager.PlayerDataPool.TeamInfo.IsCaptain())
|
||
TeamLeaderEndCombat();
|
||
}
|
||
}
|
||
//拾取物品,按品质算的,以位记录AUTOCOMBAT_PICKUP_TYPE
|
||
|
||
protected int m_nAutoPickUp = 0;
|
||
public int AutoPickUp
|
||
{
|
||
get { return m_nAutoPickUp; }
|
||
set { m_nAutoPickUp = value; }
|
||
}
|
||
public void SetAutoPickUpFlag(int nIdx, bool bFlag)
|
||
{
|
||
if (nIdx >= 0 && nIdx < 32)
|
||
{
|
||
if (bFlag == true)
|
||
{
|
||
m_nAutoPickUp |= 0x01 << nIdx;
|
||
}
|
||
else
|
||
{
|
||
m_nAutoPickUp &= ~(0x01 << nIdx);
|
||
}
|
||
}
|
||
}
|
||
public bool GetAutoPickUpFlag(int nIdx)
|
||
{
|
||
if (nIdx >= 0 && nIdx < 32)
|
||
{
|
||
return ((m_nAutoPickUp&(0x01 << nIdx)) > 0);
|
||
}
|
||
return false;
|
||
}
|
||
//自动组队
|
||
protected bool m_bAutoInviteTeamAccept = false;
|
||
public bool AutoInviteTeamAccept
|
||
{
|
||
get { return m_bAutoInviteTeamAccept; }
|
||
set { m_bAutoInviteTeamAccept = value; }
|
||
}
|
||
|
||
//自动组队
|
||
protected bool m_bAutoJoinTeamAccept = false;
|
||
public bool AutoJoinTeamAccept
|
||
{
|
||
get { return m_bAutoJoinTeamAccept; }
|
||
set { m_bAutoJoinTeamAccept = value; }
|
||
}
|
||
|
||
protected UInt64 m_nAutoEquipGuid = GlobeVar.INVALID_GUID;
|
||
public UInt64 AutoEquipGuid
|
||
{
|
||
get { return m_nAutoEquipGuid; }
|
||
set { m_nAutoEquipGuid = value; }
|
||
}
|
||
|
||
//公告控制
|
||
protected int m_nAutoNotice = 0;
|
||
public int AutoNotice
|
||
{
|
||
get { return m_nAutoNotice; }
|
||
set { m_nAutoNotice = value; }
|
||
}
|
||
|
||
private int m_nAutoMovetoQGPointId =-1; //需要自动走到的轻功点ID
|
||
public int AutoMovetoQGPointId
|
||
{
|
||
get { return m_nAutoMovetoQGPointId; }
|
||
set { m_nAutoMovetoQGPointId = value; }
|
||
}
|
||
public UInt64 HpDrugGUID
|
||
{
|
||
get { return GameManager.gameManager.PlayerDataPool.HpDrugGUID; }
|
||
set { GameManager.gameManager.PlayerDataPool.HpDrugGUID = value; }
|
||
}
|
||
|
||
private UInt64 m_nMpDrugGUID = GlobeVar.INVALID_GUID; //魔药位置
|
||
public UInt64 MpDrugGUID
|
||
{
|
||
get { return GameManager.gameManager.PlayerDataPool.MpDrugGUID; }
|
||
set { GameManager.gameManager.PlayerDataPool.MpDrugGUID = value; }
|
||
}
|
||
|
||
//private Vector3 m_AutoFightPointVec;
|
||
//public UnityEngine.Vector3 AutoFightPointVec
|
||
//{
|
||
// get { return m_AutoFightPointVec; }
|
||
// set { m_AutoFightPointVec = value; }
|
||
//}
|
||
public void InitAutoInfo()
|
||
{
|
||
//先初始化
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_EQUIP1, false);
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_EQUIP2, false);
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_EQUIP3, false);
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_EQUIP4, false);
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_EQUIP5, false);
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_STUFF, false);
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_OTHER, false);
|
||
|
||
//读取注册表
|
||
Dictionary<string, PlayerAuto> curPlayerAutoList = UserConfigData.GetPlayerAutoList();
|
||
UInt64 PlayerGuid = PlayerPreferenceData.LastRoleGUID;
|
||
if (curPlayerAutoList.ContainsKey(PlayerGuid.ToString()))
|
||
{
|
||
PlayerAuto oPlayerAuto = curPlayerAutoList[PlayerGuid.ToString()];
|
||
if (oPlayerAuto != null)
|
||
{
|
||
//AutoComabat = oPlayerAuto.AutoFightOpenToggle == 1? true : false;
|
||
AutoPickUp = oPlayerAuto.AutoPickUp;
|
||
|
||
AutoInviteTeamAccept = oPlayerAuto.AutoInviteTeamAccept == 1? true : false;
|
||
AutoJoinTeamAccept = oPlayerAuto.AutoJoinTeamAccept == 1 ? true : false;
|
||
//AutoRadius = oPlayerAuto.AutoRadius;
|
||
AutoNotice = oPlayerAuto.AutoNotice;
|
||
AutoEquipGuid = oPlayerAuto.AutoEquipGuid;
|
||
//m_AutoSelSkillID = oPlayerAuto.AutoSkillID;
|
||
//UpdateSelectDrug();
|
||
}
|
||
}
|
||
|
||
if (null != FunctionButtonLogic.Instance())
|
||
{
|
||
FunctionButtonLogic.Instance().UpdateAutoFightBtnState();
|
||
}
|
||
m_nCopySceneExitTime = -1;
|
||
}
|
||
public void UpdateSelectDrug()
|
||
{
|
||
//GameItemContainer BackPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
||
//GameItem eItem = BackPack.GetItemByGuid(HpDrugGUID);
|
||
////if (AutoIsSelectDrug == false) 永远可以自动选择药
|
||
//{
|
||
// //做自动选药处理
|
||
// bool isFind = false;
|
||
// if (eItem == null || (eItem != null && eItem.IsValid() == false) || AutoIsSelectDrug == false)
|
||
// {
|
||
// //优先选择选择过的药品类型
|
||
// if (AutoIsSelectDrug == true)
|
||
// {
|
||
// if (AutoIsSelectDrug == true)
|
||
// {
|
||
// if (BackPack.GetItemCountByDataId(AutoHpID) > 0)
|
||
// {
|
||
// HpDrugGUID = BackPack.GetItemGuidByDataID(AutoHpID);
|
||
// isFind = true;
|
||
// }
|
||
// }
|
||
// }
|
||
// if (!isFind)
|
||
// {
|
||
// for (int i = (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_END_DYHP; i >= (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_START_DYHP; --i)
|
||
// {
|
||
// Tab_CommonItem commonItem = TableManager.GetCommonItemByID(i, 0);
|
||
// if (commonItem != null)
|
||
// {
|
||
// if (BaseAttr.Level >= commonItem.MinLevelRequire)
|
||
// {
|
||
// for (int index = 0; index < BackPack.ContainerSize; ++index)
|
||
// {
|
||
// GameItem eItemEx = BackPack.GetItem(index);
|
||
// if (eItemEx != null && eItemEx.DataID == i) //身上有这个药
|
||
// {
|
||
// AutoHpID = i;
|
||
// HpDrugGUID = BackPack.GetItemGuidByDataID(AutoHpID);
|
||
// isFind = true;
|
||
// break;
|
||
// }
|
||
// }
|
||
// if (isFind)
|
||
// {
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// if (!isFind)
|
||
// {
|
||
// for (int i = (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_END_HP; i >= (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_START_HP; --i)
|
||
// {
|
||
// Tab_CommonItem commonItem = TableManager.GetCommonItemByID(i, 0);
|
||
// if (commonItem != null)
|
||
// {
|
||
// if (BaseAttr.Level >= commonItem.MinLevelRequire)
|
||
// {
|
||
// for (int index = 0; index < BackPack.ContainerSize; ++index)
|
||
// {
|
||
// GameItem eItemEx = BackPack.GetItem(index);
|
||
// if (eItemEx != null && eItemEx.DataID == i) //身上有这个药
|
||
// {
|
||
// AutoHpID = i;
|
||
// HpDrugGUID = BackPack.GetItemGuidByDataID(AutoHpID);
|
||
// isFind = true;
|
||
// break;
|
||
// }
|
||
// }
|
||
// if (isFind)
|
||
// {
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// eItem = BackPack.GetItemByGuid(MpDrugGUID);
|
||
// if (eItem == null || (eItem != null && eItem.IsValid() == false) || AutoIsSelectDrug == false)
|
||
// {
|
||
// isFind = false;
|
||
// //优先选择选择过的药品类型
|
||
// if (AutoIsSelectDrug == true)
|
||
// {
|
||
// if (BackPack.GetItemCountByDataId(AutoMpID) > 0)
|
||
// {
|
||
// MpDrugGUID = BackPack.GetItemGuidByDataID(AutoMpID);
|
||
// isFind = true;
|
||
// }
|
||
// }
|
||
|
||
// if (!isFind)
|
||
// {
|
||
// for (int i = (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_END_DYMP; i >= (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_START_DYMP; --i)
|
||
// {
|
||
// Tab_CommonItem commonItem = TableManager.GetCommonItemByID(i, 0);
|
||
// if (commonItem != null)
|
||
// {
|
||
// if (BaseAttr.Level >= commonItem.MinLevelRequire)
|
||
// {
|
||
// for (int index = 0; index < BackPack.ContainerSize; ++index)
|
||
// {
|
||
// GameItem eItemEx = BackPack.GetItem(index);
|
||
// if (eItemEx != null && eItemEx.DataID == i) //身上有这个药
|
||
// {
|
||
// AutoMpID = i;
|
||
// MpDrugGUID = BackPack.GetItemGuidByDataID(AutoMpID);
|
||
// isFind = true;
|
||
// break;
|
||
// }
|
||
// }
|
||
// if (isFind)
|
||
// {
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// if (!isFind)
|
||
// {
|
||
// for (int i = (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_END_MP; i >= (int)GameDefine_Globe.AUTOCOMBAT_DRUG_ID.AUTO_DRUG_START_MP; --i)
|
||
// {
|
||
// Tab_CommonItem commonItem = TableManager.GetCommonItemByID(i, 0);
|
||
// if (commonItem != null)
|
||
// {
|
||
// if (BaseAttr.Level >= commonItem.MinLevelRequire)
|
||
// {
|
||
// for (int index = 0; index < BackPack.ContainerSize; ++index)
|
||
// {
|
||
// GameItem eItemEx = BackPack.GetItem(index);
|
||
// if (eItemEx != null && eItemEx.DataID == i) //身上有这个药
|
||
// {
|
||
// AutoMpID = i;
|
||
// MpDrugGUID = BackPack.GetItemGuidByDataID(AutoMpID);
|
||
// isFind = true;
|
||
// break;
|
||
// }
|
||
// }
|
||
// if (isFind)
|
||
// {
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
//}
|
||
}
|
||
private int m_nCopySceneExitTime = -1;
|
||
public int ExitTime
|
||
{
|
||
get { return m_nCopySceneExitTime; }
|
||
set { m_nCopySceneExitTime = value; }
|
||
}
|
||
public float m_fAutoTimeSecond = 0;
|
||
public void UpdateAuto()
|
||
{
|
||
float ftimeSec = Time.realtimeSinceStartup;
|
||
int nTimeData = (int)(ftimeSec - m_fAutoTimeSecond);
|
||
if (nTimeData > 0)
|
||
{
|
||
m_fAutoTimeSecond = ftimeSec;
|
||
if (ExitTime > 0)
|
||
{
|
||
ExitTime = ExitTime - nTimeData;
|
||
|
||
if (ExitTime <= 0)
|
||
{
|
||
if (GameManager.gameManager.PlayerDataPool.CopySceneChange) //正在传送中
|
||
{
|
||
return;
|
||
}
|
||
GameManager.gameManager.PlayerDataPool.CopySceneChange = true;
|
||
AskLeaveCopy();
|
||
}
|
||
else
|
||
{
|
||
SendNoticMsg(false, "#{2227}", ExitTime);
|
||
}
|
||
}
|
||
|
||
if (GameManager.gameManager.PlayerDataPool.HpItemCDTime > 0)
|
||
{
|
||
GameManager.gameManager.PlayerDataPool.HpItemCDTime = GameManager.gameManager.PlayerDataPool.HpItemCDTime - nTimeData * 1000.0f;
|
||
if (GameManager.gameManager.PlayerDataPool.HpItemCDTime < 0) GameManager.gameManager.PlayerDataPool.HpItemCDTime = 0;
|
||
}
|
||
if (GameManager.gameManager.PlayerDataPool.MpItemCDTime > 0)
|
||
{
|
||
GameManager.gameManager.PlayerDataPool.MpItemCDTime = GameManager.gameManager.PlayerDataPool.MpItemCDTime - nTimeData * 1000.0f;
|
||
if (GameManager.gameManager.PlayerDataPool.MpItemCDTime < 0) GameManager.gameManager.PlayerDataPool.MpItemCDTime = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
public void UpdateAutoCombatBreakState()
|
||
{
|
||
if (!isAutoCombat && _autoCombatRecovery > 0f)
|
||
{
|
||
// Hack:自动战斗中走路不修改AutoCombat标志位,修改BreakAutoCombatTime不影响实际表现
|
||
if (MovementState == MoveState.MainPlayMove ||
|
||
MovementState == MoveState.Move)
|
||
_autoCombatRecovery = Time.unscaledTime + autoCombatRecoverDelay;
|
||
//空闲10s后 自动进入挂机状态
|
||
else
|
||
{
|
||
if (Time.unscaledTime > _autoCombatRecovery)
|
||
{
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{42100}"));
|
||
isAutoCombat = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public void ServerAutoInfo()
|
||
{
|
||
//List<LoginData.PlayerRoleData> curList = new List<LoginData.PlayerRoleData>();
|
||
//PlayerAuto AutoData = new PlayerAuto(AutoPickUp,
|
||
// AutoInviteTeamAccept,
|
||
// AutoJoinTeamAccept,
|
||
// (int)(AutoHpPercent * 100),
|
||
// (int)(AutoMpPercent * 100),
|
||
// AutoBuyDrug,
|
||
// AutoNotice,
|
||
// AutoHpID,
|
||
// AutoMpID,
|
||
// AutoIsSelectDrug,
|
||
// AutoEquipGuid);
|
||
//UserConfigData.AddPlayerAuto(GUID.ToString(), AutoData);
|
||
}
|
||
// 自动吃药
|
||
public bool AutoPercent(int nType)
|
||
{
|
||
Tab_SceneClass sceneClass = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0);
|
||
if(sceneClass != null)
|
||
{
|
||
if(sceneClass.CanUseMedic != 1)
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
var autoMedicInfo = GameManager.gameManager.PlayerDataPool.ClientCustomDateManager.PlayerCustomData.autoMedicInfo;
|
||
var backPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
||
|
||
var AutoHpID = -1;
|
||
if (autoMedicInfo != null
|
||
&& autoMedicInfo.autoHpIdList!= null
|
||
&& autoMedicInfo.autoHpIdList.Count > 0)
|
||
{
|
||
for(int index = 0; index < autoMedicInfo.autoHpIdList.Count; index++)
|
||
{
|
||
if(backPack.GetItemCountByDataId(autoMedicInfo.autoHpIdList[index]) > 0)
|
||
{
|
||
AutoHpID = autoMedicInfo.autoHpIdList[index];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
var AutoMpID = -1;
|
||
if (autoMedicInfo != null
|
||
&& autoMedicInfo.autoMpIdList != null
|
||
&& autoMedicInfo.autoMpIdList.Count > 0)
|
||
{
|
||
for (int index = 0; index < autoMedicInfo.autoMpIdList.Count; index++)
|
||
{
|
||
if (backPack.GetItemCountByDataId(autoMedicInfo.autoMpIdList[index]) > 0)
|
||
{
|
||
AutoMpID = autoMedicInfo.autoMpIdList[index];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if(AutoHpID == -1 && AutoMpID == -1)
|
||
{
|
||
if (PlayerFrameLogic.Instance())
|
||
PlayerFrameLogic.Instance().ShowLackAutoMedicItemBuff(true);
|
||
}else
|
||
{
|
||
if (PlayerFrameLogic.Instance())
|
||
PlayerFrameLogic.Instance().ShowLackAutoMedicItemBuff(false);
|
||
}
|
||
|
||
bool bSucceed = false;
|
||
|
||
if(nType == (int)MedicSubClass.HP_DY)
|
||
{
|
||
if (!GlobalData.CanUseMedicItem(AutoHpID))
|
||
{
|
||
return bSucceed;
|
||
}
|
||
}
|
||
|
||
if (nType == (int)MedicSubClass.MP_DY)
|
||
{
|
||
if (!GlobalData.CanUseMedicItem(AutoMpID))
|
||
{
|
||
return bSucceed;
|
||
}
|
||
}
|
||
|
||
if (nType == (int)MedicSubClass.HP_DY)
|
||
{
|
||
if (autoMedicInfo.isAutoHpOn == 1 ? false : true)
|
||
{
|
||
return bSucceed;
|
||
}
|
||
}
|
||
|
||
if(nType == (int)MedicSubClass.MP_DY)
|
||
{
|
||
if (autoMedicInfo.isAutoMpOn == 1 ? false : true)
|
||
{
|
||
return bSucceed;
|
||
}
|
||
}
|
||
|
||
if (nType != (int)MedicSubClass.HP_DY && nType != (int)MedicSubClass.MP_DY)
|
||
{
|
||
return false;
|
||
}
|
||
GameItemContainer BackPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
||
GameItem eItem = null;
|
||
if (nType == (int)MedicSubClass.HP_DY)
|
||
{
|
||
eItem = BackPack.GetItemByDataID(AutoHpID);
|
||
}
|
||
else if (nType == (int)MedicSubClass.MP_DY)
|
||
{
|
||
eItem = BackPack.GetItemByDataID(AutoMpID);
|
||
}
|
||
|
||
if (eItem != null && eItem.IsValid())
|
||
{
|
||
Tab_CommonItem commonItem = TableManager.GetCommonItemByID(eItem.DataID, 0);
|
||
if (commonItem != null && commonItem.ClassID == (int)ItemClass.MEDIC && (commonItem.SubClassID == (int)MedicSubClass.HP_DY || commonItem.SubClassID == (int)MedicSubClass.MP_DY))
|
||
{
|
||
bSucceed = true;
|
||
AutoUseDrug(eItem);
|
||
}
|
||
}
|
||
return bSucceed;
|
||
}
|
||
public bool AutoUseDrug(GameItem item)
|
||
{
|
||
if (null == item)
|
||
return false;
|
||
|
||
if(ItemCDInfoCtr.GetItemCDRemainTime(item.DataID) > 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
Tab_CommonItem tabItem = TableManager.GetCommonItemByID(item.DataID, 0);
|
||
if (null != tabItem)
|
||
{
|
||
int canuse = tabItem.CanUse;
|
||
if (canuse == 1)
|
||
{
|
||
CG_USE_ITEM useitem = (CG_USE_ITEM)PacketDistributed.CreatePacket(MessageID.PACKET_CG_USE_ITEM);
|
||
useitem.SetItemguid(item.Guid);
|
||
useitem.SendPacket();
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
// 自动买药
|
||
public bool OnAutoBuyDrug(int nId)
|
||
{
|
||
bool IsBuy = false;
|
||
int ShopId = 3;
|
||
int itemIdex = -1;
|
||
Tab_SystemShop curShop = TableManager.GetSystemShopByID(ShopId, 0);
|
||
if (curShop != null)
|
||
{
|
||
for (int i = 0; i < curShop.Pnum; i++)
|
||
{
|
||
if (nId == curShop.GetPidbyIndex(i))
|
||
{
|
||
IsBuy = true;
|
||
itemIdex = i;
|
||
break;
|
||
}
|
||
|
||
}
|
||
if (IsBuy) //可以买
|
||
{
|
||
CG_SYSTEMSHOP_BUY buyPacket = (CG_SYSTEMSHOP_BUY)PacketDistributed.CreatePacket(MessageID.PACKET_CG_SYSTEMSHOP_BUY);
|
||
buyPacket.SetBuyNum(1);
|
||
buyPacket.SetShopId(ShopId);
|
||
buyPacket.SetMercIndex(itemIdex);
|
||
buyPacket.SendPacket();
|
||
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
//////////////////////////////////////////////////////////////////////////
|
||
//系统设置
|
||
// protected int m_nSystemNameBoard = 0; //名字板
|
||
// public int SystemNameBoard
|
||
// {
|
||
// get { return m_nSystemNameBoard; }
|
||
// set { m_nSystemNameBoard = value; }
|
||
// }
|
||
// protected int m_nSystemMusic = 0; //声音
|
||
// public int SystemMusic
|
||
// {
|
||
// get { return m_nSystemMusic; }
|
||
// set { m_nSystemMusic = value; }
|
||
// }
|
||
// protected int m_nSystemSoundEffect = 0; //声效
|
||
// public int SystemSoundEffect
|
||
// {
|
||
// get { return m_nSystemSoundEffect; }
|
||
// set { m_nSystemSoundEffect = value; }
|
||
// }
|
||
// protected int m_nTableau = 0; //图像
|
||
// public int SystemTableau
|
||
// {
|
||
// get { return m_nTableau; }
|
||
// set { m_nTableau = value; }
|
||
// }
|
||
// public void InitSystemInfo()
|
||
// {
|
||
// SystemNameBoard = PlayerPreferenceData.SystemNameBoard;
|
||
// SystemMusic = PlayerPreferenceData.SystemMusic;
|
||
// SystemSoundEffect = PlayerPreferenceData.SystemSoundEffect;
|
||
// SystemTableau = PlayerPreferenceData.SystemTableau;
|
||
//
|
||
// GameManager.gameManager.SoundManager.EnableBGM = !(SystemMusic == 1 ? true : false);
|
||
// GameManager.gameManager.SoundManager.EnableSFX = !(SystemSoundEffect == 1 ? true : false);
|
||
//
|
||
//
|
||
public void AutoFightInYanziwu()
|
||
{
|
||
|
||
Vector3 targetPos = new Vector3();
|
||
GameObject[] m_QinggongList = GameManager.gameManager.ActiveScene.QingGongPointList;
|
||
if (m_QinggongList.Length < 0 || m_QinggongList.Length > 3)
|
||
{
|
||
return;
|
||
}
|
||
Vector2[] PointVector2 = new Vector2[3];
|
||
PointVector2[0] = new Vector2(56.2f, 27.4f); //轻功点1 起跳点
|
||
PointVector2[2] = new Vector2(41.5f, 50.9f);//轻功点2 起跳点
|
||
PointVector2[1] = new Vector2(3.8f, 41.7f);//轻功点3 起跳点
|
||
if (m_QinggongList[1].activeInHierarchy) //轻功点3开启表示 向区域四中心移动
|
||
{
|
||
targetPos.x = 18.5f;
|
||
targetPos.z = 19.6f;
|
||
}
|
||
else if (m_QinggongList[2].activeInHierarchy) //轻功点2 向区域三中心移动
|
||
{
|
||
targetPos.x = 17.8f;
|
||
targetPos.z = 51.2f;
|
||
}
|
||
else if (m_QinggongList[0].activeInHierarchy) //轻功点1 向区域二中心移动
|
||
{
|
||
targetPos.x = 54.5f;
|
||
targetPos.z = 47.2f;
|
||
}
|
||
else //向区域一中心移动
|
||
{
|
||
targetPos.x = 55.0f;
|
||
targetPos.z = 17.0f;
|
||
}
|
||
//Vector3 _vec3Tar = new Vector3(targetPos.x, Position.y, targetPos.z);
|
||
//float fDis = Vector3.Distance(_vec3Tar, Position);
|
||
//if (fDis > 16) //距离目标中心点过远 则改为向最近开启过的轻功点移动
|
||
//{
|
||
// float fMinDis = 9999999.0f;
|
||
// int nSelePointId = -1;
|
||
// float fPointDis = -1;
|
||
// for (int i = 0; i < m_QinggongList.Length; i++)
|
||
// {
|
||
// if (m_QinggongList[i].activeInHierarchy)
|
||
// {
|
||
// if (Position.z > PointVector2[i].y)
|
||
// {
|
||
// continue; //不往回走
|
||
// }
|
||
// fPointDis = Vector3.Distance(new Vector3(PointVector2[i].x, Position.y, PointVector2[i].y), Position);
|
||
// if (fPointDis < fMinDis)
|
||
// {
|
||
// fMinDis = fPointDis;
|
||
// targetPos.x = PointVector2[i].x;
|
||
// targetPos.z = PointVector2[i].y;
|
||
// }
|
||
// }
|
||
// }
|
||
//}
|
||
AutoSearchPoint point = new AutoSearchPoint(GameManager.gameManager.RunningScene, targetPos.x, targetPos.z);
|
||
|
||
if (GameManager.gameManager && GameManager.gameManager.AutoSearch)
|
||
{
|
||
BreakAutoCombatState();
|
||
GameManager.gameManager.AutoSearch.BuildPath(point);
|
||
}
|
||
}
|
||
|
||
public void UpdateSellItem()
|
||
{
|
||
if (BaseAttr.Level < GlobeVar.MAX_AUTOEQUIT_LIVE)
|
||
{
|
||
return;
|
||
}
|
||
if (!isAutoCombat)
|
||
return;
|
||
GameItemContainer BackPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
||
List<ulong> selllist = new List<ulong>();
|
||
|
||
|
||
for (int index = 0; index < BackPack.ContainerSize; ++index)
|
||
{
|
||
GameItem eItem = BackPack.GetItem(index);
|
||
if (eItem!= null) //身上有这个药
|
||
{
|
||
Tab_CommonItem line = TableManager.GetCommonItemByID(eItem.DataID, 0);
|
||
if (line != null)
|
||
{
|
||
//计算品级及拾取规则
|
||
if (line.ClassID == (int)ItemClass.EQUIP && GetAutoPickUpFlag(line.Quality)
|
||
/* && eItem.EnchanceLevel <= 0 && eItem.EnchanceExp <= 0 && eItem.StarLevel <= 0*/
|
||
|
||
&& AutoEquipGuid != GlobeVar.INVALID_GUID)
|
||
{
|
||
selllist.Add(eItem.Guid);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//做自动强化物品
|
||
//if (selllist.Count > 0)
|
||
//{
|
||
// //SysShopController.SellItem((int)GameItemContainer.Type.TYPE_BACKPACK, selllist);
|
||
// CG_EQUIP_ENCHANCE equipEnchance = (CG_EQUIP_ENCHANCE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_EQUIP_ENCHANCE);
|
||
// //发送消息包
|
||
// equipEnchance.SetPacktype(1);
|
||
// equipEnchance.SetEquipguid(AutoEquipGuid);
|
||
|
||
// equipEnchance.SendPacket();
|
||
//}
|
||
}
|
||
public void UpdateSellItem(int index)
|
||
{
|
||
if (BaseAttr.Level < GlobeVar.MAX_AUTOEQUIT_LIVE)
|
||
{
|
||
return;
|
||
}
|
||
if (!isAutoCombat)
|
||
return;
|
||
GameItemContainer BackPack = GameManager.gameManager.PlayerDataPool.BackPack;
|
||
//List<ulong> selllist = new List<ulong>();
|
||
//做自动强化物品
|
||
GameItem eItem = BackPack.GetItem(index);
|
||
if (eItem != null) //身上有这个药
|
||
{
|
||
Tab_CommonItem line = TableManager.GetCommonItemByID(eItem.DataID, 0);
|
||
if (line != null)
|
||
{
|
||
//计算品级及拾取规则
|
||
if (line.ClassID == (int)ItemClass.EQUIP && GetAutoPickUpFlag(line.Quality)
|
||
/* && eItem.EnchanceLevel <= 0 && eItem.EnchanceExp <= 0 && eItem.StarLevel <= 0*/
|
||
|
||
&& AutoEquipGuid != GlobeVar.INVALID_GUID)
|
||
{
|
||
//selllist.Add(eItem.Guid);
|
||
//CG_EQUIP_ENCHANCE equipEnchance = (CG_EQUIP_ENCHANCE)PacketDistributed.CreatePacket(MessageID.PACKET_CG_EQUIP_ENCHANCE);
|
||
//equipEnchance.SetPacktype(1);
|
||
//equipEnchance.SetEquipguid(AutoEquipGuid);
|
||
//equipEnchance.SendPacket();
|
||
}
|
||
}
|
||
}
|
||
// if (selllist.Count > 0)
|
||
// {
|
||
// SysShopController.SellItem((int)GameItemContainer.Type.TYPE_BACKPACK, selllist);
|
||
// }
|
||
}
|
||
public void UpdateSelectEquip()
|
||
{
|
||
if (AutoEquipGuid == GlobeVar.INVALID_GUID)
|
||
{
|
||
GameItemContainer EquipPack = GameManager.gameManager.PlayerDataPool.EquipPack;
|
||
if (EquipPack != null)
|
||
{
|
||
for (int index = 0; index < EquipPack.ContainerSize; index++)
|
||
{
|
||
GameItem equip = EquipPack.GetItem(index);
|
||
if (equip != null && equip.IsValid() && equip.IsBelt() == false)
|
||
{
|
||
AutoEquipGuid = equip.Guid;
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_EQUIP1, true);
|
||
SetAutoPickUpFlag((int)GameDefine_Globe.AUTOCOMBAT_PICKUP_TYPE.PICKUP_EQUIP2, true);
|
||
ServerAutoInfo();
|
||
UpdateSellItem();
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public bool IsAutoSellItem(int nDataId)
|
||
{
|
||
if (!isAutoCombat)
|
||
return false;
|
||
Tab_CommonItem line = TableManager.GetCommonItemByID(nDataId, 0);
|
||
if (line != null)
|
||
{
|
||
//计算品级及拾取规则
|
||
if ( line.ClassID == (int)ItemClass.EQUIP
|
||
&& GetAutoPickUpFlag(line.Quality) )
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
private int m_nAutoSceneId = -1;
|
||
private Vector3 m_AutoPos = new Vector3(0, 0, 0);
|
||
public void UpdateAutoAnteMortem()
|
||
{
|
||
if (!isAutoCombat)
|
||
return ;
|
||
if (IsDie())
|
||
{
|
||
m_nAutoSceneId = GameManager.gameManager.RunningScene;
|
||
m_AutoPos = m_ObjTransform.position;
|
||
}
|
||
else
|
||
{
|
||
if (m_nAutoSceneId == GameManager.gameManager.RunningScene)
|
||
{
|
||
AutoSearchPoint point = new AutoSearchPoint(m_nAutoSceneId, m_AutoPos.x, m_AutoPos.z);
|
||
if (GameManager.gameManager && GameManager.gameManager.AutoSearch)
|
||
{
|
||
GameManager.gameManager.AutoSearch.BuildPath(point);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|