Comments + Tests
This commit is contained in:
parent
538f05aa15
commit
4355551189
5 changed files with 30 additions and 19 deletions
|
@ -2,14 +2,16 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
//Define the behavior of a client
|
||||||
[RequireComponent(typeof(Collider2D))]
|
[RequireComponent(typeof(Collider2D))]
|
||||||
public class Client_controller : MonoBehaviour
|
public class Client_controller : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float consumeTime = 3.0f; //Time to consume currentMug
|
public float consumeTime = 3.0f; //Time to consume currentMug
|
||||||
public float waitingTime = 10.0f; //Patience after ordering
|
public float waitingTime = 10.0f; //Patience after ordering
|
||||||
GameObject currentMug = null;
|
GameObject currentMug = null; //Mug currently held by the client
|
||||||
|
|
||||||
//Return wether the object is taken from tavernkeeper
|
//Handle objects interactions w/ Workshop
|
||||||
|
//Return wether the object is taken from tavernkeeper
|
||||||
public bool use(GameObject object_used)
|
public bool use(GameObject object_used)
|
||||||
{
|
{
|
||||||
if(currentMug is null) //No mug in hand
|
if(currentMug is null) //No mug in hand
|
||||||
|
|
|
@ -3,14 +3,13 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
|
||||||
//Represents consumable : sprite and informations
|
//Represents consumable : sprite and informations
|
||||||
public class Consumable //: MonoBehaviour
|
public class Consumable //: MonoBehaviour
|
||||||
{
|
{
|
||||||
private HashSet<string> allowed_types = new HashSet<string>(new [] {"beer", "pression", "vodka"});
|
private HashSet<string> allowed_types = new HashSet<string>(new [] {"beer", "pression", "vodka"});
|
||||||
private string _type;
|
private string _type; //Type from allowed_types
|
||||||
private int _value;
|
private int _value;
|
||||||
private Sprite _sprite;
|
private Sprite _sprite; //Display details
|
||||||
|
|
||||||
//Read-only accessors
|
//Read-only accessors
|
||||||
public string Type
|
public string Type
|
||||||
|
@ -29,9 +28,11 @@ public class Consumable //: MonoBehaviour
|
||||||
// set{}
|
// set{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Constructor
|
||||||
//TODO : Handle sprite = null
|
//TODO : Handle sprite = null
|
||||||
public Consumable(string type, int value, Sprite sprite)
|
public Consumable(string type, int value, Sprite sprite)
|
||||||
{
|
{
|
||||||
|
//Test if type is an allowed type
|
||||||
if(!allowed_types.Contains(type))
|
if(!allowed_types.Contains(type))
|
||||||
{
|
{
|
||||||
throw new Exception("Invalid consumable type :"+type);
|
throw new Exception("Invalid consumable type :"+type);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
//Define the behavior of a mug (movable container of Consumable)
|
||||||
[RequireComponent(typeof(Collider2D))]
|
[RequireComponent(typeof(Collider2D))]
|
||||||
public class Mug : MonoBehaviour, IGrabable
|
public class Mug : MonoBehaviour, IGrabable
|
||||||
{
|
{
|
||||||
|
@ -23,7 +24,7 @@ public class Mug : MonoBehaviour, IGrabable
|
||||||
gameObject.transform.position = position;
|
gameObject.transform.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fill(Consumable new_content)
|
public void fill(Consumable new_content) //Fill Mug w/ new Consumable
|
||||||
{
|
{
|
||||||
if(content is null)
|
if(content is null)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +35,7 @@ public class Mug : MonoBehaviour, IGrabable
|
||||||
Debug.Log(gameObject.name+" cannot be filled (already full) with "+new_content.Type);
|
Debug.Log(gameObject.name+" cannot be filled (already full) with "+new_content.Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void consume()
|
public void consume() //Empty Mug of its Consumable
|
||||||
{
|
{
|
||||||
content=null;
|
content=null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,10 +79,15 @@ public class Tavernkeeper_controller : MonoBehaviour
|
||||||
rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc.
|
rigidbody2d.MovePosition(position); //Movement processed by the phyisc engine for Collision, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
//Handle action with hands
|
//Handle action with hands ("left" or "right")
|
||||||
//TODO : Factoriser actions des IGrabable et actions des Clients/Workshop
|
|
||||||
void handAction(string hand)
|
void handAction(string hand)
|
||||||
{
|
{
|
||||||
|
//Test
|
||||||
|
if(!hand_container.ContainsKey(hand))
|
||||||
|
{
|
||||||
|
throw new Exception("Invalid key for hands :"+hand);
|
||||||
|
}
|
||||||
|
|
||||||
// Test collision of ray from tavernkeeper center (A verifier) at action_dist unit distance on Interactions layer
|
// Test collision of ray from tavernkeeper center (A verifier) at action_dist unit distance on Interactions layer
|
||||||
RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, action_dist, LayerMask.GetMask("Interactions"));
|
RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, action_dist, LayerMask.GetMask("Interactions"));
|
||||||
if (hit.collider != null)
|
if (hit.collider != null)
|
||||||
|
@ -91,6 +96,8 @@ public class Tavernkeeper_controller : MonoBehaviour
|
||||||
// Debug.Log("Raycast has hit the object " + hit_object.name+ hit_object.tag);
|
// Debug.Log("Raycast has hit the object " + hit_object.name+ hit_object.tag);
|
||||||
if (hit_object != null)
|
if (hit_object != null)
|
||||||
{
|
{
|
||||||
|
//Handle objects interactions by tags
|
||||||
|
//TODO : Factoriser actions des IGrabable et actions des Clients/Workshop
|
||||||
if(hit_object.tag == "Mug")
|
if(hit_object.tag == "Mug")
|
||||||
{
|
{
|
||||||
if(hand_container[hand] is null) //Empty hand : try grab mug
|
if(hand_container[hand] is null) //Empty hand : try grab mug
|
||||||
|
@ -115,7 +122,6 @@ public class Tavernkeeper_controller : MonoBehaviour
|
||||||
if(client.use(hand_container[hand])) //Interactions w/ object in hands
|
if(client.use(hand_container[hand])) //Interactions w/ object in hands
|
||||||
{
|
{
|
||||||
//Object taken by client
|
//Object taken by client
|
||||||
// Destroy(hand_container[hand]);
|
|
||||||
hand_container[hand]=null;
|
hand_container[hand]=null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,20 +135,19 @@ public class Tavernkeeper_controller : MonoBehaviour
|
||||||
if(workshop.use(hand_container[hand])) //Interactions w/ object in hands
|
if(workshop.use(hand_container[hand])) //Interactions w/ object in hands
|
||||||
{
|
{
|
||||||
//Object taken by workshop
|
//Object taken by workshop
|
||||||
// Destroy(hand_container[hand]);
|
|
||||||
hand_container[hand]=null;
|
hand_container[hand]=null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log(hit_object.tag+" tag not handled by "+gameObject.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Full hand : drop
|
else if (hand_container[hand] != null) //Hand full and no hits
|
||||||
else if (hand_container[hand] != null)
|
|
||||||
{
|
{
|
||||||
// Debug.Log("Hand full with "+ hand_container[hand]);
|
if (hand_container[hand].tag == "Mug") //Drop mug on player position
|
||||||
// hand_container[hand].transform.SetParent(null);
|
|
||||||
|
|
||||||
if (hand_container[hand].tag == "Mug")
|
|
||||||
{
|
{
|
||||||
Mug obj = hand_container[hand].GetComponent<Mug>();
|
Mug obj = hand_container[hand].GetComponent<Mug>();
|
||||||
if(obj !=null)
|
if(obj !=null)
|
||||||
|
|
|
@ -2,15 +2,17 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
//Define the behavior of a workshop (producer of Consumable)
|
||||||
[RequireComponent(typeof(Collider2D))]
|
[RequireComponent(typeof(Collider2D))]
|
||||||
public class Workshop : MonoBehaviour
|
public class Workshop : MonoBehaviour
|
||||||
{
|
{
|
||||||
public string product_name;
|
public string product_name;
|
||||||
public int product_value;
|
public int product_value;
|
||||||
public Sprite product_sprite;
|
public Sprite product_sprite;
|
||||||
public float prepTime = 2.0f;
|
public float prepTime = 2.0f; //Time for preparation of product
|
||||||
protected int _stock = 5;
|
protected int _stock = 5; //Stock of prodcut
|
||||||
|
|
||||||
|
//Handle objects interactions w/ Workshop
|
||||||
//Return wether the object is taken from tavernkeeper
|
//Return wether the object is taken from tavernkeeper
|
||||||
public bool use(GameObject object_used)
|
public bool use(GameObject object_used)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue