100 lines
2.6 KiB
C#
100 lines
2.6 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using UnityEngine;
|
||
/// <summary>
|
||
/// 图纸类
|
||
/// </summary>
|
||
public class Drawing : Article
|
||
{
|
||
/// <summary>
|
||
/// 构造图纸
|
||
/// </summary>
|
||
/// <param name="id_">id</param>
|
||
/// <param name="name_">名字</param>
|
||
/// <param name="introduction_">介绍</param>
|
||
/// <param name=" weaponsid_">合成武器的id</param>
|
||
///
|
||
public Drawing(int id_, string name_, string introduction_,int weaponsid_) : base(id_, name_, introduction_)
|
||
{
|
||
this.weaponsid= weaponsid_;
|
||
}
|
||
/// <summary>
|
||
/// 合成id组
|
||
/// </summary>
|
||
private List<int> syntheticids;
|
||
/// <summary>
|
||
/// 图纸合成的武器
|
||
/// </summary>
|
||
private int weaponsid;
|
||
/// <summary>
|
||
/// 上传合成的id组
|
||
/// </summary>
|
||
/// <param name="ids_">合成组</param>
|
||
public void setsyntheticids(int[] ids_)
|
||
{
|
||
this.syntheticids=ids_.ToList();
|
||
}
|
||
/// <summary>
|
||
/// 返回图纸中记载的材料
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<int> getsyntheticids()
|
||
{
|
||
return this.syntheticids;
|
||
}
|
||
/// <summary>
|
||
/// 设置合成图纸的武器id
|
||
/// </summary>
|
||
/// <param name="weaponsid_"></param>
|
||
public void setweaponsid(int weaponsid_) {
|
||
this.weaponsid=weaponsid_;
|
||
}
|
||
/// <summary>
|
||
/// 合成武器方法,合成成功则返回武器id,材料不对则返回-1
|
||
/// </summary>
|
||
/// <param name="ids_">合成材料id组</param>
|
||
/// <returns>武器id</returns>
|
||
public int getsyntheticweapon(List<int> ids_) {
|
||
if (this.CompareLists(this.syntheticids, ids_))
|
||
{
|
||
return this.weaponsid;
|
||
}
|
||
else
|
||
{
|
||
return -1;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 判断两个list的列表相同
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="list1"></param>
|
||
/// <param name="list2"></param>
|
||
/// <returns>list是否相同</returns>
|
||
private bool CompareLists<T>(List<T> list1, List<T> list2)
|
||
{
|
||
// 如果长度不相等,直接返回false
|
||
if (list1.Count != list2.Count)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// 将两个列表转换为HashSet
|
||
HashSet<T> set1 = new HashSet<T>(list1);
|
||
HashSet<T> set2 = new HashSet<T>(list2);
|
||
|
||
// 比较两个HashSet
|
||
return set1.SetEquals(set2);
|
||
}
|
||
/// <summary>
|
||
/// 返回图纸可以打造武器的id
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public int getweaponsid()
|
||
{
|
||
return this.weaponsid;
|
||
}
|
||
|
||
}
|