using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using LitJson;
///
/// 场景中用到的全部buffer
///
public class BufferTemp_4001
{
public List TestPen3list;
public List InSwitchCloseYDList;
public List InSwitchOpenYDList;
public List currentunInstallJieXian;
public List currentInstallJieXian;
public List installCover;
public List currentInstallTestJieXian;
}
public class Score_4001 : ScoreBase
{
///
/// 现场场景中的特殊物体控制
///
private Device_Control_4001 device_Control;
///
/// 初始化,有配置用配置的分数,没有使用默认的分数
///
public override void Init()
{
base.Init();
List tmps = new List();
tmps.Add(new ScoreSubjectStep(1, 0));//线损异常类型研判_
tmps.Add(new ScoreSubjectStep(2, 0));//异常分析_
tmps.Add(new ScoreSubjectStep(3, 5));//工作预约_
tmps.Add(new ScoreSubjectStep(4, 5));//办理工作票_
tmps.Add(new ScoreSubjectStep(5, 5));//正确着装_
tmps.Add(new ScoreSubjectStep(6, 10));//选取工具_
tmps.Add(new ScoreSubjectStep(7, 5));//与客户沟通_
tmps.Add(new ScoreSubjectStep(8, 0));//班前会_
tmps.Add(new ScoreSubjectStep(9, 3));//采集故障
tmps.Add(new ScoreSubjectStep(10, 4));//采集故障处理
tmps.Add(new ScoreSubjectStep(11, 4));//清理现场_
steps = new Dictionary();
tmps.ForEach(a =>
{
steps.Add(a.subProcessId, a);
});
List dsteps = new List();
DataManager.Instance.d_System.subjects.Find(a => a.id == schemeId).processes.ForEach(a =>
{
dsteps.AddRange(a.subProcesses);
});
for (int i = 0; i < steps.Count; i++)
{
steps[i + 1].step = dsteps[i];
}
//清理缓存
TestPen3list.Clear();
InSwitchCloseYDList.Clear();
InSwitchOpenYDList.Clear();
currentunInstallJieXian.Clear();
currentInstallJieXian.Clear();
installCover.Clear();
currentInstallTestJieXian.Clear();
reInstall = false;
}
public override void SetDeviceControl(Device_Control device_Control)
{
this.device_Control = (Device_Control_4001)device_Control;
}
///
/// 三步验电顺序
///
List TestPen3list = new List();
///
/// 开关断电验电
///
List InSwitchCloseYDList = new List();
///
/// 开关通电验电
///
List InSwitchOpenYDList = new List();
///
/// 拆除接线顺序
///
List unInstallJieXian = new List()
{
"A_in_螺丝up", "A_in_螺丝down", "A_in_线",
"B_in_螺丝up","B_in_螺丝down","B_in_线",
"C_in_螺丝up","C_in_螺丝down","C_in_线",
"A_out_螺丝up","A_out_螺丝down","A_out_线",
"B_out_螺丝up","B_out_螺丝down","B_out_线",
"C_out_螺丝up","C_out_螺丝down","C_out_线",
"零_地_螺丝up","零_地_螺丝down","零_地_线",
"零_out_螺丝up","零_out_螺丝down","零_out_线"
};
///
/// 拆除接线螺丝操作
///
List currentunInstallJieXian = new List();
///
/// 安装接线螺丝顺序
///
List installJieXian = new List()
{
"零_out_线","零_out_螺丝up","零_out_螺丝down",
"零_地_线","零_地_螺丝up","零_地_螺丝down",
"C_out_线","C_out_螺丝up","C_out_螺丝down",
"B_out_线","B_out_螺丝up","B_out_螺丝down",
"A_out_线","A_out_螺丝up","A_out_螺丝down",
"C_in_线","C_in_螺丝up","C_in_螺丝down",
"B_in_线","B_in_螺丝up","B_in_螺丝down",
"A_in_线","A_in_螺丝up", "A_in_螺丝down"
};
///
/// 安装接线螺丝操作
///
List currentInstallJieXian = new List();
///
/// 安装流程安装盖子
///
List installCover = new List();
///
/// 安装流程对接验电螺丝
///
List installTestJieXian = new List() { "验电笔+A_in_螺丝", "验电笔+B_in_螺丝", "验电笔+C_in_螺丝" };
///
/// 安装流程对接验电操作
///
List currentInstallTestJieXian = new List();
///
/// 采集器是否重装过
///
bool reInstall = false;
public override void CheckScore(string triggerName, object para)
{
base.CheckScore(triggerName, para);
if (triggerName == "电脑")
{
if (para.ToString() == "线损异常类型研判完成")
{
steps[1].SetScore(true);//线损异常类型研判完成
}
}
if (triggerName == "手机")
{
if (para.ToString() == "异常分析完成")
{
steps[2].SetScore(true);//1->2 异常分析完成
}
else if (para.ToString() == "工作预约完成")
{
steps[3].SetScore(true);//2->3 工作预约完成
}
}
else if (triggerName == "低压工作票确认按钮")
{
steps[4].SetScore(true);//3->4 办理工作票完成
}
//else if (triggerName == "拆装工单按钮")
//{
// steps[4].SetScore(true);
//}
else if (triggerName == "现场按钮")
{
//检查是否穿戴
float tmp = 0;
tmp += (PacksackBagMgr.Instance.wearDic.ContainsKey("国网安全帽") ? 0.25f : 0);
tmp += (PacksackBagMgr.Instance.wearDic.ContainsKey("工作服") ? 0.25f : 0);
tmp += (PacksackBagMgr.Instance.wearDic.ContainsKey("绝缘手套") ? 0.25f : 0);
tmp += (PacksackBagMgr.Instance.wearDic.ContainsKey("绝缘靴") ? 0.25f : 0);
steps[5].SetScore(tmp);
//检查背包是否携带
string[] shoudleTools = new string[] { "剥线钳", "绝缘螺丝刀", "验电笔", "国网安全帽", "工作服", "绝缘手套", "绝缘靴", "工作证", "盒装封印", "采集器" };
float tmp2 = 1;
shoudleTools.ToList().ForEach(a =>
{
tmp2 -= (PacksackBagMgr.Instance.toolAndMaterialDic.ContainsKey(a) ? 0 : 0.1f);
});
steps[6].SetScore(Mathf.Clamp01(tmp2));
}
else if (triggerName == "工作证")
{
//与客户沟通
steps[7].SetScore(true);
}
else if (triggerName == "NPC负责人")
{
//班前会
steps[8].SetScore(true);
}
//else if (triggerName == "检查接线")
//{
// if ((bool)para)
// {
// //12之前时拆除流程,之后时安装流程
// if (!steps[12].isDone)
// {
// //接线检查打分,判断三步验电是否正确
// steps[9].SetScore(isCheckE());
// }
// else
// {
// //安装检查
// steps[14].SetScore(true);
// }
// }
//}
else if (triggerName == "验电笔+插座" || triggerName == "验电笔+柜门")
{
//记录验电顺序
TestPen3list.Add(triggerName);
}
else if (triggerName == "故障记录按钮")
{
//采集故障
steps[9].SetScore(isCheckE());
}
//else if (triggerName == "验电笔+in开关_螺丝1" || triggerName == "验电笔+in开关_螺丝2" || triggerName == "验电笔+in开关_螺丝3")
//{
// //3012之前是拆除,之后是安装
// if (!steps[12].isDone)
// {
// //断电情况下
// if (device_Control.inSwitch.isOpen == false)
// {
// InSwitchCloseYDList.Add(triggerName);
// steps[10].SetScore(isInSwitchCheckE(), true);
// }
// }
// else
// {
// //通电情况下
// if (device_Control.inSwitch.isOpen == true)
// {
// InSwitchOpenYDList.Add(triggerName);
// }
// }
//}
//else if (triggerName == "电能表铭牌")
//{
// steps[11].SetScore(true);
//}
//else if (unInstallJieXian.Contains(triggerName))
//{
// //3012之前是拆除,之后是安装
// //接线螺丝和线
// if (!steps[12].isDone)
// {
// //判断拆接线
// if ((bool)para)
// currentunInstallJieXian.Remove(triggerName);
// else
// currentunInstallJieXian.Add(triggerName);
// }
// else
// {
// //判断安装接线
// if ((bool)para)
// currentInstallJieXian.Add(triggerName);
// else
// currentInstallJieXian.Remove(triggerName);
// //判分
// if (triggerName.Contains("A_in_螺丝"))
// {
// steps[13].SetScore(IsInstallJieXianCheckE(), true);
// }
// }
//}
//else if (triggerName == "电能表区域碰撞")
//{
// //取下电能表时判断验电顺序
// if (para != null && !(bool)para)
// {
// steps[12].SetScore(IsUninstallJieXianCheckE());
// }
//}
//else if (triggerName.Contains("电能表拆装螺丝"))
//{
// //安装流程下
// if (steps[12].isDone)
// {
// //拆装螺丝
// if ((bool)para)
// currentInstallJieXian.Add(triggerName);
// else
// currentInstallJieXian.Remove(triggerName);
// }
//}
//else if (triggerName.Contains("电能表盖子固定螺丝"))
//{
// //安装流程
// if (steps[12].isDone)
// {
// if ((bool)para)
// installCover.Add(triggerName);
// else
// installCover.Remove(triggerName);
// steps[15].SetScore(Check15(), true);
// }
//}
//else if (installTestJieXian.Any(a => triggerName.StartsWith(a)))
//{
// //接线验电
// if (steps[12].isDone)
// {
// currentInstallTestJieXian.Add(triggerName);
// }
//}
//else if (triggerName.Contains("电能表封印") && triggerName.Contains("触发区域"))
//{
// if (steps[12].isDone)
// {
// if (!device_Control.meteringDevice.cover.cover_seal_Left.isCut && !device_Control.meteringDevice.cover.cover_seal_Right.isCut)
// {
// steps[16].SetScore(true, true);
// }
// }
//}
else if (triggerName == "采集器")
{
if (para.ToString() == "采集器完成重装")
{
reInstall = true;
}
}
else if (triggerName == "联系主站台按钮")
{
if (steps[9].isDone && para.ToString() == "异常分析完成" && reInstall)
{
steps[10].SetScore(true);
}
}
else if (triggerName == "柜门封印触发区域")
{
if (steps[10].isDone)
{
if (!device_Control.sundries.gameObject.activeInHierarchy && device_Control.door_screw.isInstall && !device_Control.door_seal.isCut)
{
steps[11].SetScore(true);//清理现场
}
}
}
}
///
/// 检查三步验电
///
///
private bool isCheckE()
{
int guimen = 0;
if (TestPen3list.Count >= 3)
{
for (int i = 0; i < TestPen3list.Count; i++)
{
if (i == 0)
{
if (TestPen3list[i] != "验电笔+插座")
break;
}
else
{
if (TestPen3list[i] == "验电笔+柜门")
{
guimen = i;
}
else
{
if (guimen != 0)
{
//三步验电完成
Debug.Log("三步验电正确");
return true;
}
}
}
}
}
return false;
}
///
/// 开关验电
///
///
private bool isInSwitchCheckE()
{
if (InSwitchCloseYDList.Contains("验电笔+in开关_螺丝1") && InSwitchCloseYDList.Contains("验电笔+in开关_螺丝2") && InSwitchCloseYDList.Contains("验电笔+in开关_螺丝2"))
{
return true;
}
else
{
return false;
}
}
///
/// 判断拆接线顺序
///
///
private bool IsUninstallJieXianCheckE()
{
if (currentunInstallJieXian.Count != unInstallJieXian.Count)
{
return false;
}
//一一比对
for (int i = 0; i < currentunInstallJieXian.Count; i++)
{
if (currentunInstallJieXian[i] != unInstallJieXian[i])
{
//不分上下螺丝
if (currentunInstallJieXian[i].Replace("up", "").Replace("down", "") != unInstallJieXian[i].Replace("up", "").Replace("down", ""))
return false;
}
}
return true;
}
///
/// 判断安装接线顺序
///
///
public bool IsInstallJieXianCheckE()
{
if (!currentInstallJieXian.Contains("电能表拆装螺丝1") || !currentInstallJieXian.Contains("电能表拆装螺丝2"))
return false;
if (currentInstallJieXian.Count < installJieXian.Count + 2)
{
return false;
}
//一一比对
string[] tmps = new string[currentInstallJieXian.Count];
currentInstallJieXian.CopyTo(tmps);
var tmplist = tmps.ToList();
tmplist.Remove("电能表拆装螺丝1");
tmplist.Remove("电能表拆装螺丝2");
for (int i = 0; i < tmplist.Count; i++)
{
//不分上下螺丝
if (tmplist[i].Replace("up", "").Replace("down", "") != installJieXian[i].Replace("up", "").Replace("down", ""))
return false;
}
return true;
}
public bool Check15()
{
//开关关了,盖子拧上了
if (device_Control.inSwitch.isOpen && installCover.Contains("电能表盖子固定螺丝1") && installCover.Contains("电能表盖子固定螺丝2"))
{
//无验电顺序
if (installTestJieXian.TrueForAll(a => currentInstallTestJieXian.Any(b => b.Replace("up", "").Replace("down", "") == a)))
{
return true;
}
}
return false;
}
///
/// 保存场景的Buffer信息
///
///
public override string SaveSceneBufferList()
{
BufferTemp_4001 tmp = new BufferTemp_4001();
tmp.TestPen3list = TestPen3list;
tmp.InSwitchCloseYDList = InSwitchCloseYDList;
tmp.InSwitchOpenYDList = InSwitchOpenYDList;
tmp.currentunInstallJieXian = currentunInstallJieXian;
tmp.currentInstallJieXian = currentInstallJieXian;
tmp.installCover = installCover;
tmp.currentInstallTestJieXian = currentInstallTestJieXian;
string sceneInfo = JsonConvert.SerializeObject(tmp, Formatting.Indented);
Debug.Log("==????:" + sceneInfo);
return sceneInfo;
//throw new System.NotImplementedException();
}
///
/// 加载场景的Buffer信息
///
public override void LoadSceneBufferList(string sceneInfo)
{
BufferTemp_4001 tmp = new BufferTemp_4001();
tmp = JsonMapper.ToObject(sceneInfo);
TestPen3list = tmp.TestPen3list;
InSwitchCloseYDList = tmp.InSwitchCloseYDList;
InSwitchOpenYDList = tmp.InSwitchOpenYDList;
currentunInstallJieXian = tmp.currentunInstallJieXian;
currentInstallJieXian = tmp.currentInstallJieXian;
installCover = tmp.installCover;
currentInstallTestJieXian = tmp.currentInstallTestJieXian;
//throw new System.NotImplementedException();
}
}