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