using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
///
/// 铁匠玩家脚本
///
public class BlacksmithPlayer_Mon : MonoBehaviour
{
///
/// 铁匠类:锻造锤,锻造台
///
private Blacksmith blacksmith;
///
/// 材料盒子:储存所有材料
///
private List articleboxs;
///
/// 图纸盒子,储存所有图纸
///
private List drawingboxs;
///
/// 锻造栏盒子
///
private List forgingbarboxs;
///
/// 道具组脚本
///
private MaterialGroup_Mon materialGroupMon;
///
/// 玩家信息组件脚本
///
private PlayerUser_Mon playerUserMon;
///
/// 锻造
///
private ForgingInterface_Mon forgingInterfaceMon;
///
/// 顾客脚本组件
///
private Customer_Mon customer_Mon;
///
/// 武器合成途径脚本组件
///
private EquipmentSynthesisPath_Mon EquipmentSynthesisPath_Mon;
///
/// 结算界面脚本组件
///
private Checkout_Mon Checkout_Mon;
///
/// 初始化游戏加载
///
public void LoadGame()
{
//道具盒子加载
this.LoadGameArticle();
//图纸盒子加载
this.LoadGameDrawing();
//角色数据加载
this.LoadGameRole();
}
///
/// 加载角色数据
///
public void LoadGameRole()
{
this.EquipmentSynthesisPath_Mon = GameObject.Find("装备合成路径").GetComponent();
this.materialGroupMon = GameObject.Find("材料组").GetComponent();
this.playerUserMon= GameObject.Find("玩家信息").GetComponent();
this.customer_Mon = GameObject.Find("顾客门框").GetComponent();
// 查找所有对象,包括未激活的
GameObject[] allObjects = GameObject.FindObjectsOfType(true);
// 遍历所有对象,查找名称匹配的对象
foreach (var obj in allObjects)
{
if (obj.name == "锻造界面")
{
this.forgingInterfaceMon = obj.GetComponent();
}
if (obj.name == "结算界面")
{
this.Checkout_Mon= obj.GetComponent();
}
}
//this.forgingInterfaceMon = GameObject.FindObjectsOfType("");// GameObject.Find("锻造界面").GetComponentInParent();
this.forgingInterfaceMon.gameObject.SetActive(false);
this.blacksmith = new Blacksmith();
//初始金币500
this.blacksmith.add_money(500);
this.blacksmith.add_articles(this.articleboxs[0], 10);
this.blacksmith.add_articles(this.articleboxs[1], 100);
this.blacksmith.add_articles(this.articleboxs[2], 2);
this.blacksmith.add_articles(this.articleboxs[3], 2);
this.blacksmith.add_client(new Client("约翰",201,10f));
this.blacksmith.add_client(new Client("大约翰",202, 10f));
this.blacksmith.add_client(new Client("小约翰", 201, 10f));
this.blacksmith.add_client(new Client("孙约翰", 202, 10f));
this.blacksmith.add_client(new Client("张约翰", 201, 10f));
this.blacksmith.add_client(new Client("赵约翰", 202, 10f));
Debug.Log("---------------------------------------------角色加载完成!!!");
}
private void Awake()
{
this.LoadGame();
}
void Start()
{
this.LoadGameUI();
}
///
/// 加载游戏界面
///
public void LoadGameUI()
{
//背包刷新
this.materialGroupMon.set_material(this.blacksmith.get_articles());
this.playerUserMon.LoadGameUI(Resources.Load("image/GUI/人物头像等级"), "传奇铁匠", 9, 100, this.blacksmith.getmoney());
}
///
/// 拖动物品到锻造栏里运行此方法,会删除掉背包里的物品*1
///
/// 物品id
/// 物品数量
///
public Article dragmaterial(int id_,int mun_)
{
Article article_ = this.blacksmith.find_article(id_);
this.blacksmith.del_material(id_, mun_);
this.LoadGameUI();
return article_;
}
///
/// 添加材料
///
/// 材料id
/// 数量
public void add_article(int id_,int mun_)
{
this.blacksmith.add_articles(this.FindArticleBoxs(id_), mun_);
//物品;栏改变刷新物品栏
this.materialGroupMon.set_material(this.blacksmith.get_articles());
}
///
/// 初始化加载游戏材料
///
private void LoadGameArticle()
{
this.articleboxs=new List();
Material material_101 = new Material(101, "羽毛", "", Resources.Load("image/材料/材料_101"));
Material material_102= new Material(102, "木头", "", Resources.Load("image/材料/材料_102"));
Weapons material_201= new Weapons(201, "弓", "", Resources.Load("image/武器/武器_201"),100);
Weapons material_202 = new Weapons(202, "剑", "", Resources.Load("image/武器/武器_202"), 100);
this.articleboxs.Add(material_101);
this.articleboxs.Add(material_102);
this.articleboxs.Add(material_201);
this.articleboxs.Add(material_202);
Debug.Log("---------------------------------------------材料盒子加载完成!!!");
}
///
/// 初始化加载武器图纸
///
private void LoadGameDrawing()
{
this.drawingboxs = new List();
Drawing drawing_301 = new Drawing(301, "弓箭", "普通武器",201);
Drawing drawing_302 = new Drawing(302, "剑", "普通武器", 202);
drawing_301.setsyntheticids(new int[2] {101,102});
drawing_302.setsyntheticids(new int[2] { 102, 102 });
this.drawingboxs.Add(drawing_301);
this.drawingboxs.Add(drawing_302);
Debug.Log("---------------------------------------------全图纸加载完成!!!");
}
///
/// 获取锻造栏中的四个材料
///
private void obtainforgingbar()
{
this.forgingbarboxs = new List();
GameObject[] objs_ = GameObject.FindGameObjectsWithTag("锻造栏");
foreach (GameObject obj_ in objs_) {
if (obj_.GetComponent().getarticleid() != 0)
{
this.forgingbarboxs.Add(obj_.GetComponent().getarticleid());
}
}
Debug.Log("材料长度" + this.forgingbarboxs.Count);
}
///
/// 获取锻造材料的长度
///
///
public int GetForgingbarBoxCount()
{
this.obtainforgingbar();
return this.forgingbarboxs.Count;
}
///
/// 清除锻造栏
///
public void RemoveForgingbar()
{
GameObject[] objs_ = GameObject.FindGameObjectsWithTag("锻造栏");
foreach (GameObject obj in objs_)
{
// 获取该对象下的所有子对象
Transform[] children = obj.GetComponentsInChildren();
// 从子对象中排除父对象本身
foreach (Transform child in children)
{
if (child.gameObject != obj) // 确保不销毁父对象本身
{
Destroy(child.gameObject); // 销毁子对象
}
}
}
}
///
/// 锻造方法
///
/// 返回是否锻造成功
public bool forge()
{
//获取锻造栏锻造材料
this.obtainforgingbar();
//图纸
Drawing drawing_ = this.FindDrawingBoxs(this.blacksmith.GetClient().getweaponid());
int id_= drawing_.getsyntheticweapon(this.forgingbarboxs);
if (id_ == -1)
{
Debug.Log("锻造失败!材料有问题");
return false;
}
Article article_=this.FindArticleBoxs(id_);
Debug.Log("合成id"+article_.getname());
Weapons weapons_ = (Weapons)article_;
//this.blacksmith.SubmitOrder(weapons_);
this.blacksmith.add_articles(weapons_, 1);
this.LoadGameUI();
return true;
return true;
//铁匠类
//this.blacksmith;
//材料图纸不在手上也可以锻造
}
///
/// 店铺开门营业
///
public void OpenShop()
{
Debug.Log("开门营业");
//设置铁匠状态
this.blacksmith.OpenShop();
}
//锻造中
public void Forging()
{
Debug.Log("锻造中...");
//设置铁匠状态
this.blacksmith.Forging();
}
///
/// 铁匠铺休息不关门
///
public void Rest()
{
Debug.Log("休息中...");
//设置铁匠休息状态
this.blacksmith.CloseDoor();
}
///
/// 店铺关闭
///
public void CloseShop()
{
if (this.blacksmith.getBlacksmithType() != BlacksmithType.CLOSEDOOR)
{
Debug.Log("订单未结束无法关门,当前状态"+this.blacksmith.getBlacksmithType().ToString());
}
else
{
Debug.Log("打烊了");
this.blacksmith.CloseShop();
this.EquipmentSynthesisPath_Mon.CloseDrawing();
this.Checkout_Mon.StartCheckout();
}
}
///
/// 删除首位顾客
///
public void Remove_Clientfirst()
{
this.blacksmith.remove_clientfirst();
}
///
/// 刷新顾客
///
public void Customer()
{
Debug.Log("顾客上门");
Debug.Log("姓名:"+this.blacksmith.GetClient().getName());
Drawing drawing_ = this.FindDrawingBoxs(this.blacksmith.GetClient().getweaponid());
this.EquipmentSynthesisPath_Mon.SetDrawing(drawing_);
Debug.Log("要求锻造:" + drawing_.getname());
//开始接客切换铁匠状态
this.blacksmith.OpenShop();
}
///
/// 场景开门营业运行的方法
///
public void Door()
{
//检测是否为等待状态
if (this.blacksmith.getBlacksmithType() == BlacksmithType.WAIT)
{
this.OpenShop();
}
//检测是否为工作状态
else if(this.blacksmith.getBlacksmithType() == BlacksmithType.WORK)
{
this.customer_Mon.CloseDoor();
this.CloseShop();
}
}
///
/// 场景铁锤锻造运行的方法
///
public void HammerForging()
{
//if (this.blacksmith.getBlacksmithType() != BlacksmithType.WAIT)
//{
// Debug.Log("未开门,或者正在锻造"+this.blacksmith.getBlacksmithType().ToString());
// return;
//}
this.forgingInterfaceMon.gameObject.SetActive(true);
this.forgingInterfaceMon.LoadGameData(this);
//this.forge();
}
///
/// 输入id,获取图纸盒中的图纸
///
///
///
private Drawing FindDrawingBoxs(int id_)
{
foreach(Drawing drawing_ in this.drawingboxs)
{
if (drawing_.getweaponsid() == id_)
{
return drawing_;
}
}
Debug.LogError("发热的电阻丝:图纸盒未注册或者id错误");
return null;
}
///
/// 通过id查找材料盒子里是否有该材料
///
/// 材料id
/// 返回该材料
private Article FindArticleBoxs(int id_)
{
foreach (Article article_ in this.articleboxs)
{
if (article_.getId() == id_)
{
return article_;
}
}
Debug.LogError("发热的电阻丝:材料盒子未注册该材料或检查输入的材料id《" + id_ + "》是否正确。");
return null;
}
///
/// 提交武器:外部调用
///
/// 武器
public void SubmitWeapons(int weapons_)
{
int in_=this.blacksmith.SubmitOrder((Weapons)(this.FindArticleBoxs(weapons_)));
this.Checkout_Mon.AddIncome(in_);
this.Customer();
//刷新客人
this.customer_Mon.Renovate_Visitor();
this.LoadGameUI();
}
///
/// 输入id返回材料或者武器的icon
///
///
///
public Sprite FindArticleBoxsSprite(int id_)
{
foreach (Article article_ in this.articleboxs)
{
if (article_.getId() == id_)
{
return article_.getIcon();
}
}
Debug.LogError("发热的电阻丝:材料盒子未注册该材料或检查输入的材料id《" + id_ + "》是否正确。");
return null;
}
///
/// 返回此时铁匠的状态方便调用
///
///
public BlacksmithType GetBlacksmithType()
{
return this.blacksmith.getBlacksmithType();
}
///
/// 返回客户数量
///
///
public int GetClientsLength()
{
return this.blacksmith.GetClientsLength();
}
// Update is called once per frame
void Update()
{
//Debug.Log("状态打印" + this.blacksmith.getBlacksmithType().ToString());
}
}